题目描述
在字符串中找到第一个只出现一次的字符。如输入“abaccdeff”,则输出'b'。
题目分析
剑指Offer(纪念版)P186
代码实现
char FirstNotRepeatingChar(char* pString)
{
if(pString == NULL)
return ' ';
const int tableSize = 256;
unsigned int hashTable[tableSize];
for(unsigned int i = 0; i<tableSize; ++ i)
hashTable[i] = 0;
char* pHashKey = pString;
while(*(pHashKey) != ' ')
hashTable[*(pHashKey++)] ++;
pHashKey = pString;
while(*pHashKey != ' ')
{
if(hashTable[*pHashKey] == 1)
return *pHashKey;
pHashKey++;
}
return ' ';
}