题解 | #字符流中第一个不重复的字符#
字符流中第一个不重复的字符
http://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
public class Solution {
//Insert one char from stringstream
int[] zifu = new int[256];
Queue<Character> q = new LinkedList<>();
public void Insert(char ch)
{
if(zifu[ch] == 0){
zifu[ch]++;
q.offer(ch);
}else{
q.remove(ch);
}
}
//return the first appearence once char in current stringstream
public char FirstAppearingOnce()
{
if(q.isEmpty()){
return '#';
}else{
return q.peek();
}
}
}