//Design an algorithm and write code to remove the duplicate characters in a string
//without using any additional buffer NOTE: One or two additional variables are fine
// An extra copy of the array is not
#include <iostream>
using namespace std;
//void move(char *s)
//{
// while(*s)
// {
// *s =*(s+1);
// s++;
// }
//}
bool remove(char s[])
{
if (s==NULL) return false;
int n =strlen(s);
if (n<2)return false;
int m =0;
for (auto i =0;i<n;i++)
{
int val =s[i] -'a';
if((m &(1<<val))>0)
{
for(auto j= i;s[j]!=NULL;j++)
s[j] =s[j+1];
i--;
}
m |=(1<<val);
}
return true;
}
void main()
{
char s[]="aaabbb";
remove(s);
cout<<s;
system("pause");
}
//Design an algorithm and write code to remove the duplicate characters in a string //without using any additional buffer NOTE: One or two additional variables are fine // An extra copy of the array