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

密码验证合格程序

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

const rl = require("readline").createInterface({ input: process.stdin });

rl.on('line',line => {
    console.log(isValid(line))
})

function isValid(str) {
    //长度
    if(str.length <= 8) {
        return 'NG'
    }
    //种类
    let count = 0
    if(/[a-z]/.test(str)) {
        count++
    }
    if(/[A-Z]/.test(str)) {
        count++
    }
    if(/\d/.test(str)) {
        count++
    }
    if(/[^a-zA-Z\d\s]/.test(str)) {
        count++
    }
    if(count < 3) {
        return 'NG'
    }
    //重复
    const obj = {}
    for(let i = 3;i < str.length / 2;i++) {
        let index = 0
        while(index < str.length - i) {
            let k = str.substring(index,index + i)
            if(obj[k]) {
                return 'NG'
            }else {
                obj[k] = 1
            }
            index++
        }
    }
    return 'OK'
}

全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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