字元出現:雜湊思想,字元儲存陣列/Map
字元順序,佇列
import java.util.Queue;
import java.util.LinkedList;
import java.lang.Character;
public class Solution {
int[] charCnt = new int[128];
Queue<Character> queue = new LinkedList<Character>();
//Insert one char from stringstream
public void Insert(char ch) {
if (charCnt[ch]++ == 0)
queue.add(ch);
}
//return the first appearence once char in current stringstream
public char FirstAppearingOnce() {
Character CHAR = null;
char c = 0;
while ((CHAR = queue.peek()) != null) {
c = CHAR.charValue();
if (charCnt[c] == 1)
return c;
else queue.remove();
}
return '#';
}
}