Topic description
Please implement a function to find the first one-occurrence character in the character stream. For example, when only the first two characters "go out" are read from the character stream, the first character that occurs only once is "G". When the first six characters "google" are read from this character stream, the first character is "G". A character that appears only once is "L".
Code
class Solution
{
public:
int all[200];
string s;
//Insert one char from stringstream
void Insert(char ch)
{ s = s + ch;
all[ch]++;
}
//return the first appearence once char in current stringstream
char FirstAppearingOnce()
{ char res = '#';
for(int i = 0;i<s.length();i++){
if (all[s[i]] ==1){
res = s[i];
return res;
}
}
return res;
}
};