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

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

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));
    }
})();

全部评论

相关推荐

双非一本失业第二年:《机器视觉垃圾分类》
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务