Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to remove all adjacent duplicates in a string in C. say for example..if "caaabbcdd" is the given string then it should remove sequentially as

 1. cbbcdd

 2. ccdd

 3. dd

thus an empty string is returned in the end. Time complexity can be O(n^2) for starting.Can anyone help.

so far this i what i have done

void recursiven2(char *str)
{
int i,j,k,len;
    len=strlen(str);
    for(i=0;i<len-1;i++)
    {
    if(str[i]==str[i+1])
    {
        for(j=i;j<len-2;j++)
            str[j]=str[j+2];
        str[j]='';
    }
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
556 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can refer to this. It has a very nice explanation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...