public class Solution { //Insert one char from stringstream int[] arr = new int[256]; int temp = 1; public void Insert(char ch) { if(arr[ch] == 0){ arr[ch] = temp++; } else{ arr[ch] = -1; } } //return the first appearence once char in current stringstream public char FirstAppearingOnce() { int num = Integer.MAX_VALUE; char ch = '#'; for(int i = 0; i < 256; i++){ if(arr[i] != 0 && arr[i] != -1 && arr[i] < num){ num = arr[i]; ch = (char)i; } } return ch; } }
来源:https://www.cnblogs.com/q-1993/p/10950039.html