文章出處

題目描述
請實現一個函數用來找出字符流中第一個只出現一次的字符。例如,當從字符流中只讀出前兩個字符"go"時,第一個只出現一次的字符是"g"。當從該字符流中讀出前六個字符“google"時,第一個只出現一次的字符是"l"。
輸出描述:
如果當前字符流沒有存在出現一次的字符,返回#字符。

class Solution
{
private:
    vector<char> vec;
    map<char, int> mapper;
public:
  //Insert one char from stringstream
    void Insert(char ch)
    {
        vec.push_back(ch);
        mapper[ch] ++;
    }
  //return the first appearence once char in current stringstream
    char FirstAppearingOnce()
    {
        for(int i=0; i<vec.size(); i++){
            if(mapper[vec[i]]==1){
                return vec[i];
            }
        }
        
        return '#';
    }

};

文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()