import java.util.*;
public class Solution {
//Insert one char from stringstream
int[] isAppear = new int[256];
Queue<Character> deque = new LinkedList<>();
public void Insert(char ch)
{
int index = ch; //65 ‘a' 97
if(isAppear[index] < 2){
isAppear[index]++;
deque.add(ch);
}
}
//return the first appearence once char in current stringstream
public char FirstAppearingOnce()
{
while(!deque.isEmpty() && isAppear[deque.peek()] != 1){
deque.poll();
}
return deque.isEmpty() ? '#' : deque.peek();
}
}
京公网安备 11010502036488号