牛客(54)字符流中第一个不重复的字符
Map<Character,Integer> map = new HashMap<Character, Integer>(); ArrayList<Character> arrayList = new ArrayList<Character>(); //Insert one char from stringstream public void Insert(char ch) { if (map.containsKey(ch)){ map.put(ch,map.get(ch)+1); }else { map.put(ch,1); } arrayList.add(ch); } //return the first appearence once char in current stringstream public char FirstAppearingOnce() { char ch='#'; for (int i=0;i<arrayList.size();i++){ if (map.get(arrayList.get(i))==1){ return arrayList.get(i); } } return ch; }