zoukankan      html  css  js  c++  java
  • 面试题55 字符流中第一个不重复的字符

    题目描述

    请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g"。当从该字符流中读出前六个字符“google"时,第一个只出现一次的字符是"l"。 
    输出描述:
    如果当前字符流没有存在出现一次的字符,返回#字符。

     1 class Solution
     2 {
     3 public:
     4     int hashtable[256] = {0};
     5     vector<char> v;
     6   //Insert one char from stringstream
     7     void Insert(char ch)
     8     {
     9         hashtable[ch]++;
    10         v.push_back(ch);
    11        
    12     }
    13   //return the first appearence once char in current stringstream
    14     char FirstAppearingOnce()
    15     {
    16         for (int i = 0; i < v.size(); i++){
    17             if (hashtable[v[i]] == 1)
    18                 return v[i];
    19         }
    20         return '#';
    21     }
    22 
    23 };
  • 相关阅读:
    zpf 视图
    html5本地存储
    sqlite 使用记录
    百度开放平台
    PHP exit() 输出
    yum笔记
    手动编译安装软件
    while循环
    linux下面测试网络带宽 (转载)
    软件包管理器的核心功能(笔记)
  • 原文地址:https://www.cnblogs.com/wanderingzj/p/5374812.html
Copyright © 2011-2022 走看看