O(1)解法简版
字符流中第一个不重复的字符
http://www.nowcoder.com/questionTerminal/00de97733b8e4f97a3fb5c680ee10720
class Solution
{
public:
//Insert one char from stringstream
void Insert(char ch)
{
str += ch;
save[ch]++;
}
//return the first appearence once char in current stringstream
char FirstAppearingOnce()
{
for(int i=0; i<str.size(); ++i)
if(save[str[i]] == 1) return str[i];
return '#';
}
private:
string str = "";
map<char, int> save;
};
查看20道真题和解析