【剑指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) {
        map<char, int> hashmap;
        for(int i = 0; i < s.size(); i++)
            hashmap[s[i]] += 1;
        char ch = ' ';
        for(int i = 0; i < s.size(); i++)
            if(hashmap[s[i]] == 1)
            {
                ch = s[i];
                break;
            }
        return  ch;
    }
};
posted @ 2020-04-19 15:48  NaughtyCoder  阅读(90)  评论(0)    收藏  举报