import java.util.*;
public class Solution {
HashMap<Character, Integer> map = new HashMap<>();
Queue<Character> queue = new LinkedList<>();
//Insert one char from stringstream
public void Insert(char ch)
{
int count = map.getOrDefault(ch, 0);
if (count == 0) {
queue.offer(ch);
} else {
queue.remove(ch);
}
map.put(ch, count + 1);
}
//return the first appearence once char in current stringstream
public char FirstAppearingOnce()
{
return queue.isEmpty() ? '#' : queue.peek();
}
}
京公网安备 11010502036488号