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

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

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

//Init module if you need
// 初始化
const map = new Map();
let s = '';
function Init() {
}
//Insert one char from stringstream
function Insert(ch) {
    s += ch;
    if(!map.has(ch)){
        map.set(ch, 1);
    }
    else{
        map.set(ch, map.get(ch) + 1);
    }
}
//return the first appearence once char in current stringstream
function FirstAppearingOnce() {
    for(let char of s){
        if(map.get(char) === 1) return char;
    }
    return '#';
}

module.exports = {
    Init: Init,
    Insert: Insert,
    FirstAppearingOnce: FirstAppearingOnce,
};

全部评论

相关推荐

06-27 15:29
门头沟学院 Java
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
06-11 13:34
门头沟学院 C++
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务