剑指OFFER----面试题50. 第一个只出现一次的字符

链接:https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/

代码

class Solution {
public:
    char firstUniqChar(string s) {
        unordered_map<char, int> count;
        for (auto c: s) {
            count[c]++;
        }
        for (auto c: s) {
            if (count[c] == 1) {
                return c;
            }
        }
        return ' ';
    }
};
posted @ 2020-03-08 10:54  景云ⁿ  阅读(69)  评论(0编辑  收藏  举报