#include<iostream>
using namespace std;
char firstNotRepeatingChar(char* pString){
if(pString == NULL){
return '\0';
}
const int tableSize = 256;
unsigned int hashTable[tableSize];
for(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';
}
int main(){
char* pString = "abaccdeff";
char res = firstNotRepeatingChar(pString);
cout<<res<<endl;
}
第一个只出现一次的字符
最新推荐文章于 2022-08-17 09:51:01 发布