题解 | #JZ75 字符流中第一个不重复的字符#

字符流中第一个不重复的字符

http://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720

https://blog.csdn.net/qq_43466457/article/details/104393464

```//Init module if you need
let mp
function Init()
{
    // write code here
   mp = new Map()
}
//Insert one char from stringstream
function Insert(ch)
{
    // write code here
    let num= mp.get(ch)
    if(!num){
        mp.set(ch,1)
    }
    else{
        mp.set(ch,num+1)
    }
}
//return the first appearence once char in current stringstream
function FirstAppearingOnce()
{
    // write code here
    for(let ch of mp.keys()){
        if(mp.get(ch)===1){return ch}
    }
    return '#'
}

module.exports = {
	Init : Init,
    Insert : Insert,
    FirstAppearingOnce: FirstAppearingOnce
};
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务