【leetcode】删除字符串中的所有相邻重复项

 

char * removeDuplicates(char * S){
int top=-1;
int i;
int len=strlen(S);
for(i=0;i<len;i++){
    S[++top]=S[i];//入栈
    if(top>0&&S[top]==S[top-1]){
        top=top-2;
    }
}
S[top+1]='\0';
return S;
}

 

posted @ 2020-09-09 13:44  温暖了寂寞  阅读(196)  评论(0编辑  收藏  举报