字符流中第一个只出现一次的字符
class Solution{
public:
string str;
int i=0;
int cnt[256]={0};
//Insert one char from stringstream
void insert(char c){
str+=c;
cnt[c]++;
}
//return the first appearence once char in current stringstream
char firstAppearingOnce(){
while(i<str.size())
{
if(cnt[str[i]]==1) return str[i];
i++;
}
return '#';
}
};
有帮助的话可以点个赞,我会很开心的~

浙公网安备 33010602011771号