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

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

http://www.nowcoder.com/questionTerminal/00de97733b8e4f97a3fb5c680ee10720

队列+数组
class Solution
{
public:
  //Insert one char from stringstream
    int ch_int[256]={0};
    queue<char> s1;
    void Insert(char ch)
    {
         ch_int[ch]++;
        if(ch_int[ch] == 1)
           s1.push(ch);
        
    }
  //return the first appearence once char in current stringstream
    char FirstAppearingOnce()
    {
        while(!s1.empty())
        {
            if (ch_int[s1.front()] == 1)
                 return s1.front();
            s1.pop();
        }
            return '#';
    }

};


全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务