题解 | #合法IP#

合法IP

https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
rl.on("line", function (line) {
    const arr = line.split(".");
    console.log(
        arr.length === 4 &&
            arr.every(
                (num) =>
                    /^[0-9]{1,3}$/.test(num) && (num.length == 1 ||
                    num.length > 1 &&
                        !num.startsWith("0") &&
                        Number(num) >= 0 &&
                        Number(num) <= 255)
            )
            ? "YES"
            : "NO"
    );
});

全部评论

相关推荐

asdasdasda...:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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