请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g"。
public class Solution {
//Insert one char from stringstream
String str="";
int[] count=new int[256];
public void Insert(char ch)
{
if(ch >=256){
return ;
}else{
str+=ch;
count[ch]++;
}
}
//return the first appearence once char in current stringstream
public char FirstAppearingOnce()
{
for(char c:str.toCharArray()){
if(count[c]==1){
return c;
}
}
return '#';
}
}