剑指offer---字符流中第一个不重复的字符

class Solution
{
    string str;
    int hash[256];
public:
  //Insert one char from stringstream
    void Insert(char ch)
    {
        str.push_back(ch);
        hash[ch]++;
    }
  //return the first appearence once char in current stringstream
    char FirstAppearingOnce()
    {
        for(int i = 0; i < str.size(); ++i){
            if(hash[str[i]] == 1)
                return str[i];
        }
          
        return '#';
    }
  
};

 

posted @ 2017-08-04 16:00  双马尾是老公的方向盘  阅读(121)  评论(0编辑  收藏  举报