首页 > 代码库 > 【哈希表】
【哈希表】
char FirstNotRepeatingChar(char* pString){ // invalid input if(!pString) return 0; // get a hash table, and initialize it const int tableSize = 256; //字符1个字节8位 unsigned int hashTable[tableSize]; //unsigned?? for(unsigned int i = 0; i < tableSize; ++ i) hashTable[i] = 0; //为什么要置0? // get the how many times each char appears in the string char* pHashKey = pString; while(*(pHashKey) != ‘\0‘) hashTable[*(pHashKey++)] ++; // find the first char which appears only once in a string pHashKey = pString; while(pHashKey) { if(hashTable[*pHashKey] == 1) return *pHashKey; pHashKey++; } // if the string is empty // or every char in the string appears at least twice return 0;}
【哈希表】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。