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

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

https://www.nowcoder.com/practice/bd891093881d4ddf9e56e7cc8416562d

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
    let params = []
    while(line = await readline()){
        let tokens = line.split(' ');
        // let a = parseInt(tokens[0]);
        // let b = parseInt(tokens[1]);
        // console.log(a + b);
        params.push(tokens)
    }
    // console.log(params)
    let str = params[0][0]
    let matches = str.matchAll(/[0-9]+/g)
    let maxStr = ""
    for(match of matches){
        // console.log(match)
        let str = match[0]
        if(str.length > maxStr.length){
            maxStr = str;
        }
    }
    console.log(maxStr)
}()

全部评论

相关推荐

27届学院本誓死冲击...:自我评价和校园经历全删了,荣誉经历只留奖学金,项目也全得换都不如外卖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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