码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-04-11 09:55:03      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:har   style   div   font   ret   pen   思路   appear   append   

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

思路:基于map的思路,,类型题

 int[] table=new int[256];
    StringBuffer sb=new StringBuffer(); 
    public void Insert(char ch)
    {
        sb.append(ch);
        table[ch]++;
    }
  //return the first appearence once char in current stringstream
    public char FirstAppearingOnce()
    {
        char[] str=sb.toString().toCharArray();
        for(char c:str){
            if(table[c]==1)
                return c;
        }
        return ‘#‘;
    }

 

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

标签:har   style   div   font   ret   pen   思路   appear   append   

原文地址:http://www.cnblogs.com/team42/p/6691786.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!