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

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

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,
};

全部评论

相关推荐

鼠鼠第一次实习,啥也不懂一直是自己一个人吃的饭,不会做工作老是被嫌弃,大人的世界是这样的吗?
我是星星我会发亮:好的mt有两种,一种愿意教你的,一种几乎什么活都不给你派让你很闲允许你做自己事情的
点赞 评论 收藏
分享
能干的三文鱼刷了100道题:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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