/*
双指针思想:(i,j)遍历字符区间
指针j遍历读取的字符序列,每遇到一个相同的字符就++;
指针i指向第一个只出现一次的字符,若字符已不满足条件,则i++
*/
//可用队列实现上述思想
class Solution{
public:
unordered_map<char,int> count;
queue<char> q;
//Insert one char from stringstream
void insert(char ch){
if(++count[ch]>1){ //不满足条件
while(q.size() && count[q.front()] > 1)
q.pop(); //实现i++
}else{
q.push(ch);
}
}
//return the first appearence once char in current stringstream
char firstAppearingOnce(){
if(q.empty()){
return '#';
}else{
return q.front();
}
}
};