14.字符串hash寻找第一个只出现一次的字符
1 //char 0-255一共256个 2 char getonebyhash(char *str) 3 { 4 if (str == NULL) 5 { 6 return '\0'; 7 } 8 char ch = '\0'; 9 //哈希表设置为0 10 int hashtable[256] = { 0 }; 11 //依次获取 12 char *phash = str; 13 14 //遍历循环字符串数据存放在hash表 15 while (*phash != '\0') 16 { 17 hashtable[*phash]++; 18 phash++; 19 } 20 21 //备份首地址,寻找到第一个值为1的字符 22 phash = str; 23 while (*phash != '\0') 24 { 25 if (hashtable[*phash] == 1) 26 { 27 ch = *phash; 28 break; 29 } 30 phash++; 31 } 32 return ch; 33 34 35 }