题目:在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出'b'。
char FirstNotRepeatingChar(char *pString)
{
if (pString == NULL)
return '\0';
const int tableSize = 256;
unsigned int hashTable[tableSize];
for (unsigned int i = 0; i < tableSize; ++i)
hashTable[i] = 0;
// 第一次扫描
char *pHashKey = pString;
while (*pHashKey != '\0')
hashTable[*pHashKey++] ++;
// 第二次扫描
pHashKey = pString;
while (*pHashKey != '\0')
{
if (hashTable[*pHashKey] == 1)
return *pHashKey;
pHashKey++;
}
return '\0';
}