题解 | #第一个只出现一次的字符#
第一个只出现一次的字符
http://www.nowcoder.com/practice/1c82e8cf713b4bbeb2a5b31cf5b0417c
哈希表
class Solution {
public:
int FirstNotRepeatingChar(string str) {
unordered_map<char, int> rec;
for(int i=0; i<str.length(); i++){
rec[str[i]] += 1;
}
int res = -1;
for(int i=0; i<str.length(); i++){
if(rec[str[i]] == 1){
res = i;
break;
}
}
return res;
}
};