解題思路
先統計出每個字符的出現次數
再按照s中字符的順序進行遍歷
代碼
class Solution {
public:
char firstUniqChar(string s) {
char res=' ';
map<char, int> hashMap;
for (auto it=s.begin();it!=s.end();it++)
{
++hashMap[*it];
}
for (auto it = s.begin(); it != s.end(); it++)
{
if (hashMap[*it] == 1) return *it;
}
return res;
}
};