请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符\"go\"时,第一个只出现一次的字符是\"g\"。当从该字符流中读出前六个字符“google\"时,第一个只出现一次的字符是\"l\"。
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