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 (hashtTable[*pHashKey] == 1)
return *pHashKey;
pHashKey++;
}
return '\0';
}
本文介绍了一种用于寻找字符串中第一个不重复字符的高效算法。通过使用哈希表来跟踪字符出现次数,该算法能够快速定位所需字符,特别适用于处理大量数据。此方法不仅节省了内存资源,还显著提高了搜索速度。

被折叠的 条评论
为什么被折叠?



