class Solution
{
public:
//Insert one char from stringstream
void Insert(char ch)
{
if(cimap.count(ch) == 0)
cque.push(ch);
++cimap[ch];
}
//return the first appearence once char in current stringstream
char FirstAppearingOnce()
{
while(!cque.empty()){
if (cimap[cque.front()] > 1)
cque.pop();
else
return cque.front();
}
return '#';
}
map<char, int> cimap;
queue<char> cque;
};用一个map和queue数据结构
1、map记录输入字符个数,queue无重复记录各字符输入顺序
2、输出时由队首开始检查输入个数,然后输出
欢迎交流指正!!!

京公网安备 11010502036488号