题解 | #字符流中第一个不重复的字符#

字符流中第一个不重复的字符

https://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720

class Solution
{
public:
  //Insert one char from stringstream

    vector<char> res;
    unordered_map<char, int> mp;

    void Insert(char ch) {
         res.push_back(ch);
         mp[ch]++;
    }
  //return the first appearence once char in current stringstream
    char FirstAppearingOnce() {
        for(auto x : res){
            if(mp[x] == 1) return x;
        }
        return '#';
    }

};

全部评论

相关推荐

永不遗忘:才这么点算什么拉黑,我初筛连着挂几十次了,最后还是能进面
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务