题目:删除一个字符串中重复字符,要求不能使用额外的缓冲区,不能复制字符串,可以使用一两个变量。
解答:
function String removeDuplicates(char[] str){
if(str != null && str.length > 1){
for(int i=0; i<str.length-1; i++){
char c = str[i];
if(c != 0){
for(int j=i+1; j<str.length; j++){
if(c == str[j]){
str[j] = 0;
}
}
}
}
}
return str;
}