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


    请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符 "go" 时,第一个只出现一次的字符是 "g"。当从该字符流中读出前六个字符“google" 时,第一个只出现一次的字符是 "l"。

    C++:

     1 class Solution
     2 {
     3 private:
     4     int cnt[256] = {0} ;
     5     queue<char> q ;
     6 public:
     7   //Insert one char from stringstream
     8     void Insert(char ch)
     9     {
    10         cnt[ch]++ ;
    11         q.push(ch) ;
    12         while(!q.empty() && cnt[q.front()] > 1)
    13             q.pop() ;
    14         
    15     }
    16   //return the first appearence once char in current stringstream
    17     char FirstAppearingOnce()
    18     {
    19          if (q.empty()){
    20              return '#' ;
    21          }else{
    22              return q.front() ;
    23          }
    24     }
    25 
    26 };
  • 相关阅读:
    JSP第二次作业
    软件测试课堂练习
    内容提供者读取短信信息
    购物车
    第六周jsp
    第四周jsp
    第一周 软件测试
    第八次安卓
    安卓第七次作业
    安卓第六次作业
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/10608971.html
Copyright © 2020-2023  润新知