美文网首页
2019-06-10

2019-06-10

作者: minus_1 | 来源:发表于2019-06-10 12:56 被阅读0次

作者@ 万晨
创建于 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;
    }
};

相关文章

网友评论

      本文标题:2019-06-10

      本文链接:https://www.haomeiwen.com/subject/eyfzxctx.html