char * deleteDuplicatedChar(char *string)
{
if (strlen(string) <= 1)
return string;
char *pCurPos = &string[1];
char *pLastPos = &string[1];
while (*pCurPos != '\0')
{
char *pComparePos;
for (pComparePos = string; pComparePos < pLastPos; pComparePos++)
{
if (*pCurPos == *pComparePos)
{
pCurPos++;
break;
}
}
if (pComparePos == pLastPos)
{
*pLastPos++ = *pCurPos++;
}
}
*pLastPos = '\0';
return string;
}
char * deleteDuplicatedChar2(char *string)
{
if (strlen(string) <= 1)
return string;
char HashTable[256] = {0};
char *pCurPos = string;
char *pLastPos = string;
while (*pCurPos != '\0')
{
if (HashTable[*pCurPos] != 1)
{
HashTable[*pCurPos]++;
*pLastPos++ = *pCurPos++;
}
else
{
++pCurPos;
}
}
*pLastPos = '\0';
return string;
}
删除字符串中重复出现的字符
最新推荐文章于 2023-06-11 23:53:34 发布