Last active
November 6, 2016 17:07
-
-
Save nashid/075e867ec4e9d483f1b2c64bfda99ce0 to your computer and use it in GitHub Desktop.
Remove duplicate characters contained in the second string from the first String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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