Skip to content

Instantly share code, notes, and snippets.

@hokamoto
Last active October 12, 2015 23:28
Show Gist options
  • Save hokamoto/4103527 to your computer and use it in GitHub Desktop.
Save hokamoto/4103527 to your computer and use it in GitHub Desktop.
A *wrong* code for eliminating duplicate characters from strings
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]) {
for (int k = j; k < len - 1; k++) {
str[k] = str[k + 1];
}
str[len - 1] = 0;
}
}
}
return new String(str).trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment