算法1
懒人做法,迟更新
记录下已经重复的数字
C++ 代码
class Solution{
public:
//Insert one char from stringstream
queue<char> que;
unordered_map<char,int> mp;
void insert(char ch){
if (mp[ch] == 0) {
que.push(ch);
}
mp[ch] += 1;
}
//return the first appearence once char in current stringstream
char firstAppearingOnce(){
while (!que.empty() && mp[que.front()] >= 2) {
que.pop();
}
return que.empty() ? '#' : que.front();
}
};