C++ 代码
class Solution{
public:
queue<char> q;
unordered_map<char, int> hash;
//Insert one char from stringstream
void insert(char ch){
if(++ hash[ch] == 1)
q.push(ch);
}
//return the first appearence once char in current stringstream
char firstAppearingOnce(){
while(!q.empty() && hash[q.front()] > 1) q.pop();
if(q.empty()) return '#';
return q.front();
}
};