A string is a collection of characters terminated by a special character '\0'. String can have duplicate characters in it. Today's problem requires purging of those duplicate characters from string and return the string.
Key Point: char[256],hashtable
From Coding Interviews: Questions, Analysis & Solutions
void DeletedDuplication(char* pString) {
int hashTable[256];
char* pSlow = pString;
char* pFast = pString;
if(pString == NULL)
return;
memset(hashTable, 0, sizeof(hashTable));
while (*pFast != '\0') {
*pSlow = *pFast;
if(hashTable[*pFast] == 0) {
++ pSlow;
hashTable[*pFast] = 1;
}
++pFast;
}
*pSlow = '\0';
}
Read full article from Algorithms and Me: Strings : Remove duplicates from a string
Key Point: char[256],hashtable
From Coding Interviews: Questions, Analysis & Solutions
void DeletedDuplication(char* pString) {
int hashTable[256];
char* pSlow = pString;
char* pFast = pString;
if(pString == NULL)
return;
memset(hashTable, 0, sizeof(hashTable));
while (*pFast != '\0') {
*pSlow = *pFast;
if(hashTable[*pFast] == 0) {
++ pSlow;
hashTable[*pFast] = 1;
}
++pFast;
}
*pSlow = '\0';
}
Read full article from Algorithms and Me: Strings : Remove duplicates from a string