Skip to content

Instantly share code, notes, and snippets.

@nashid
Last active November 6, 2016 17:07
Show Gist options
  • Save nashid/075e867ec4e9d483f1b2c64bfda99ce0 to your computer and use it in GitHub Desktop.
Save nashid/075e867ec4e9d483f1b2c64bfda99ce0 to your computer and use it in GitHub Desktop.
Remove duplicate characters contained in the second string from the first String
package kata.string;
public class RemoveDuplicateString {
public static String removeDuplicateCharacters(String first, String second) {
if (first == null || second == null) { return first; }
char[] map = new char[256];
for (int i = 0; i < second.length(); i++) {
char ch = second.charAt(i);
map[ch] = 1;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < first.length(); i++) {
char ch = first.charAt(i);
if (!(map[ch] == 1)) {
sb.append(ch);
}
}
return sb.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment