AcWing
  • 首页
  • 题库
  • 题解
  • 分享
  • 问答
  • 活动
  • 应用
  • 吐槽
  • 登录/注册

AcWing 64. 字符流中第一个只出现一次的字符

作者: 作者的头像   nihaotian ,  2020-03-17 23:35:54 ,  阅读 86


0


class Solution{
public:
    unordered_map<char,int> count;
    queue<int> q;
    //Insert one char from stringstream
    void insert(char ch){
        if(++ count[ch] > 1) //当ch出现过时
        {
            while(q.size() && count[q.front()] > 1) q.pop(); //弹出队列中所有出现过不止一次的字母
        }
        else
        q.push(ch); //加入没有出现过的字母
    }
    //return the first appearence once char in current stringstream
    char firstAppearingOnce(){
        if(q.empty()) return '#';
        return q.front();
    }
};

0 评论

你确定删除吗?

© 2018-2021 AcWing 版权所有  |  京ICP备17053197号-1
联系我们  |  常见问题
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息