mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Move methods from others to correct packages (#6475)
refactor: Move methods from `others` package to their respective packages
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
/**
|
||||
* @author Varun Upadhyay (https://github.com/varunu28)
|
||||
*/
|
||||
public final class RemoveDuplicateFromString {
|
||||
private RemoveDuplicateFromString() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes duplicate characters from the given string.
|
||||
*
|
||||
* @param input The input string from which duplicate characters need to be removed.
|
||||
* @return A string containing only unique characters from the input, in their original order.
|
||||
*/
|
||||
public static String removeDuplicate(String input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return input;
|
||||
}
|
||||
|
||||
StringBuilder uniqueChars = new StringBuilder();
|
||||
for (char c : input.toCharArray()) {
|
||||
if (uniqueChars.indexOf(String.valueOf(c)) == -1) {
|
||||
uniqueChars.append(c); // Append character if it's not already in the StringBuilder
|
||||
}
|
||||
}
|
||||
|
||||
return uniqueChars.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user