面试题50:第一个只出现一次的字符
在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。
class Solution {
public:
char firstUniqChar(string s) {
unordered_map<char,bool> map;
for(char c:s)
map[c] = (map.find(c)==map.end()); // map.find()函数:如果在map中找不到c返回.end();
for(char c:s)
if(map[c] == true) return c;
return ' ';
}
};