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的便捷之处