请实现一个函数用来找出字符流中第一个只出现一次的字符
var res = [];
function Init()
{
res = [];
}
//Insert one char from stringstream
function Insert(ch)
{
if( res[ch] ){
res[ch]++;
}else{
res[ch] = 1;
}
}
//return the first appearence once char in current stringstream
function FirstAppearingOnce()
{
for( var ch in res ){
if( res.hasOwnProperty(ch) ){
if( res[ch] == 1 ){
return ch;
}
}
}
return '#';
}
查看6道真题和解析