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.
这题,只需要像1.1一个保存一个重复字符就行了。写一个位图法的。
void deleteDuplicateChars(char * chr)
{
int checker = 0;
char * start = chr;
while (*start != '\0')
{
int value = *chr - 'A';
if (checker & (1<<value) > 0)
{
char * newchr = chr;
while (*newchr != '\0' && *(newchr + 1) != '\0')
{
*newchr = *(newchr + 1);
newchr ++;
}
*newchr = '\0';
}
else
checker |= (1<<value);
start ++;
}
}