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

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

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

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param ch string字符串型 
 * @return 无
 */
//这个函数是进行循环遍历的
let str = ''
const map = new Map()
export function Insert(ch: string) {
    // write code here
    str += ch
    if(!map.get(ch)){
        map.set(ch,1)
    }else{
        map.set(ch,map.get(ch) + 1)
    }
}

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param 无 
 * @return string字符串型
 */
export function FirstAppearingOnce(): string {
    // write code here
    //找到第一次出现的
    for(let  i = 0;i < str.length;i++){
        if(map.get(str.charAt(i)) === 1){
            return str.charAt(i)
        }
        
    }
    return '#'
}

全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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