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

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

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

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
rl.on("line", function (line) {
  fn(line);
});
const fn = (str: string) => {
  let arr = str.match(/\d+/g);
  const lens = arr.map((item) => item.length);
  const max = Math.max(...lens);
  arr = arr.filter((item) => item.length === max);
  console.log(`${arr.join('')},${max}`);
};

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务