作者@ 万晨
创建于 2019-06-10T12:50:00
摘自《剑指Offer》何海涛
50. 第一次只出现一次的字符
Input: "abaccdeff"
Output: "b"
class Solution {
public:
int FirstNotRepeatingChar(string str) {
int LEN = str.length();
map<char, int> M;
for (int i=0; i<LEN; i++) M[str[i]] += 1;
for (int i=0; i<LEN; i++) {
if (M[str[i]]==1) return i;
}
return -1;
}
};
网友评论