You are on page 1of 1

#include <iostream>

using namespace std;

void removeDuplicates(char* S)
{
// When string is empty, return
if (S[0] == '\0')
return;

// if the adjacent characters are same, Shift character by one to left


if (S[0] == S[1]) {

int i = 0;
while (S[i] != '\0') {
S[i] = S[i + 1];
i++;
}

// Check on Updated String S


removeDuplicates(S);
}

removeDuplicates(S + 1);
}

int main()
{
char S1[] = "abbcbbb";
removeDuplicates(S1);
cout << S1 << endl;

return 0;
}

You might also like