【剑指offer】【哈希】50.第一次只出现一次的字符
题目链接:https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/
哈希
class Solution {
public:
char firstUniqChar(string s) {
map<char, int> hashmap;
for(int i = 0; i < s.size(); i++)
hashmap[s[i]] += 1;
char ch = ' ';
for(int i = 0; i < s.size(); i++)
if(hashmap[s[i]] == 1)
{
ch = s[i];
break;
}
return ch;
}
};
知识的价值不在于占有,而在于使用