Last active
October 12, 2015 23:28
-
-
Save hokamoto/4103564 to your computer and use it in GitHub Desktop.
Eliminating duplicate characters from strings
This file contains hidden or 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
public static String deleteDuplicateCharacters(String val) { | |
char[] str = val.toCharArray(); | |
int len = str.length; | |
for (int i = 0; i < len; i++) { | |
for (int j = i + 1; j < len; j++) { | |
if (str[i] == str[j] && str[j] != 0) { | |
for (int k = j; k < len - 1; k++) { | |
str[k] = str[k + 1]; | |
} | |
str[len - 1] = 0; | |
j--; | |
} | |
} | |
} | |
return new String(str).trim(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment