题解 | #在字符串中找出连续最长的数字串#

在字符串中找出连续最长的数字串

https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    while ((line = await readline())) {
        let arr = [];
        max = 0;
        str = "";
        num = 0;
        for (let i = 0; i < line.length; i++) {
            if (!isNaN(line[i])) {
                str = str.concat(line[i]);
                num++;
            }
            if ((isNaN(line[i]) && num !== 0) || i === line.length - 1) {
                if (num > max) {
                    arr = [];
                    arr.push(str);
                    max = num;
                } else if (num === max) {
                    arr.push(str);
                }
                str = "";
                num = 0;
            }
        }
        console.log(arr.join("").concat(",", max));
    }
})();

全部评论

相关推荐

过往烟沉:我说什么来着,java就业面就是广!
点赞 评论 收藏
分享
11-18 09:44
Java
小白也想要offer:简历别放洋屁,搞不还还放错了,当然你投外企除外,以上纯属个人观点
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务