Name: Anonymous 2011-05-22 22:37
this doesn't work if the first letter has a duplicate at the end. what am i doing wrong?
/**
* Removes duplicate characters. Only latter instances<br/>
* are deleted
* @param s - the original
* @return the string with dupes removed
*/
public static String removeDuplicates(String s){
for (int x = 0; x < s.length(); x++){
for (int k = x + 1 ; k < s.length(); k++){
if (s.charAt(x) == s.charAt(k))
s = s.substring(0, k) + s.substring(k + 1);
}
}
return s;
}