剑指 Offer 50. 第一个只出现一次的字符

时间:2021-02-15 11:50:39   收藏:0   阅读:0

题意

如题目所示

思路

代码

class Solution {
public:
    char firstUniqChar(string s) {
        if(s.empty()) {
            return ‘ ‘;
        }
        unordered_map<char, int> table;
        for(auto ch: s) {
            table[ch]++;
        }
        for(auto ch: s) {
            if(table[ch] == 1) {
                return ch;
            }
        }
        return ‘ ‘;
    }
};
评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!