最多有128种字符,弄一个数组来放。出现一次,该位置上的数就+1.
用队列放当前唯一一个的值。
import java.util.*;
public class Solution {
private int[] charMap = new int[128];
Queue<Character> queue = new LinkedList<>();
//Insert one char from stringstream
public void Insert(char ch)
{
charMap[ch]++;
queue.add(ch);
}
//return the first appearence once char in current stringstream
public char FirstAppearingOnce()
{
while(!queue.isEmpty()&&charMap[queue.peek()]!=1){
queue.poll();
}if(queue.isEmpty()){
return '#';
}
return queue.peek();
}
}