char* removeDuplicates(char* s) {
int ns=0;
while(s[ns]!=0) ns++;
if(ns<=1) return s;
char* stack=(char*)malloc(sizeof(char)*ns);
for(int i=0;i<ns;i++) stack[i]=0;
int top=0;
stack[0]=s[0];
for(int i=1;i<ns;i++){
if(top!=-1 && s[i]==stack[top]){
stack[top--]=0;
}else{
stack[++top]=s[i];
}
}
return stack;
}
结果:
标签:1047,删除,char,相邻,字符串,ns From: https://www.cnblogs.com/llllmz/p/18045243