public class Solution {
private int[] cnts = new int[128];
private Queue<Character> queue = new LinkedList<Character>();
//Insert one char from stringstream
public void Insert(char ch)
{
cnts[ch]++;
queue.add(ch);
while (!queue.isEmpty() && cnts[queue.peek()] > 1) {
queue.poll();
}
}
//return the first appearence once char in current stringstream
public char FirstAppearingOnce()
{
return queue.isEmpty() ? '#' : queue.peek();
}
}
剑指offer-3.2-41.2
最新推荐文章于 2021-03-19 15:25:16 发布