题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', function (line) {
    console.log(line.length > 8 && check1(line) && check2(line) ? 'OK' : 'NG');
});


function check1(line: string){
    let count = [0,0,0,0]
    const arr = line.split('')
    for(let c of arr){
        if('A' <= c && 'Z' >= c)   count[0] = 1
        else if('a' <= c && 'z' >= c)  count[1] = 1
        else if(/^[0-9]$/.test(c)) count[2] = 1
        else if(c !== '' && c !== '\n' ) count[3] = 1
    }

    return count.reduce((sum,cur)=>sum+cur) >= 3 
}

function check2(line: string){
    const set = new Set()

    for(let i = 0; i < line.length - 3; i++){
        const str = line.slice(i, i + 3)
        if(set.has(str))   return false

        set.add(str)
    }

    return true
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:11
点赞 评论 收藏
分享
湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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