题目描述
blablabla
class Solution{
public:
//Insert one char from stringstream
map<char,int> mm;
int cnt = 1;
void insert(char ch){
if(mm[ch] != 0)
mm[ch] = -1;
else
mm[ch] = cnt;
cnt++;
}
//return the first appearence once char in current stringstream
char firstAppearingOnce(){
int temp = 1000000;
char res = '#';
for(int i = 0; i < 26; i++)
{
if(mm['a'+i] != 0 && mm['a'+i] != -1)
if(temp > mm['a'+i])
{
temp = mm['a'+i];
res = 'a'+i;
}
if(mm['A'+i] != 0 && mm['A'+i] != -1)
if(temp > mm['A'+i])
{
temp = mm['A'+i];
res = 'A'+i;
}
}
return res;
}
};
暴力也能过……