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

#include<stdio.h>
#include<string.h>
#include <pthread.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <stdlib.h>
#include <sstream>
using namespace std;


class Solution
{
public:
    //Insert one char from stringstream
    int hashTable[256]= {0};//这里为什么大小是256呢
    string s;
    void Insert(char ch)
    {
        if(ch>256) return;
        s=s+ch;
        hashTable[ch]++;//根据字符修改哈希数组元素的值
        cout<<s<<endl;
    }
    //return the first appearence once char in current stringstream
    char FirstAppearingOnce()
    {
        for(char c:s)
        {
            if(hashTable[c]==1)
                return c;
        }
        return '#';
    }
};

int main()
{

    Solution s;
    string str="google";
    s.Insert('g');
    s.Insert('o');
    s.Insert('o');
    s.Insert('g');
    s.Insert('l');
    s.Insert('e');
    cout<<s.FirstAppearingOnce();
    system("pause");
    return 0;

}

 

posted @ 2017-09-22 09:24  bananaa  阅读(165)  评论(0编辑  收藏  举报