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

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

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

import java.util.*;

public class Solution {
    LinkedHashMap<Character, Boolean> map=new LinkedHashMap();
    //Insert one char from stringstream
    public void Insert(char ch)
    {
         map.put(ch, !map.containsKey(ch));
    }

    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce()
    { 
       for (Map.Entry<Character, Boolean> entry : map.entrySet()) {
            if (entry.getValue() != false){
                return entry.getKey();
            }
        }
        return '#';
    }
}

这个出现过很多次了,使用LinkedHashMap的便捷之处

全部评论

相关推荐

ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务