题解 | #字符流中第一个不重复的字符# Java 直接用 LinkedHashSet 解决
字符流中第一个不重复的字符
http://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
public class Solution { LinkedHashSet<Character> set = new LinkedHashSet<>(); //Insert one char from stringstream public void Insert(char ch) { if (set.contains(ch)) set.remove(ch); else set.add(ch); } //return the first appearence once char in current stringstream public char FirstAppearingOnce() { if (set.isEmpty()) return '#'; return set.iterator().next(); } }