字符流中第一个不重复的字符

 1 class Solution
 2 {
 3 public:
 4   //Insert one char from stringstream
 5     void Insert(char ch)
 6     {
 7         s+=ch;
 8         m[ch]++;
 9     }
10   //return the first appearence once char in current stringstream
11     char FirstAppearingOnce()
12     {
13         for(int i=0;i<s.size();i++){
14             if(m[s[i]]==1) return s[i];
15         }
16         return '#';
17     }
18 private:
19     string s;
20     unordered_map<char,int> m;
21 };

 

posted @ 2019-07-24 17:15  Austin_anheqiao  阅读(178)  评论(0编辑  收藏  举报