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; }
牛客(54)字符流中第一个不重复的字符
猜你喜欢
转载自www.cnblogs.com/kaibing/p/9099481.html
周排行