Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • 字符串中最长连续数字

字符串中最长连续数字

如 123ab1234d458 输出 1234

    let str = '123ab1234d458';
    let getMax = (str) => {
      let nums = str.split('');
      let start = 0, start1 = 0, end1 = 0, result = 0;
      for (let i = 0; i < nums.length; i++) {
        if (nums[i] <= nums[i - 1] || Number.isNaN(Number(nums[i]))) {

          if (i - start > result) {
            result = Math.max(i - start, result);
            console.log(start1);
            start1 = start;
            end1 = i
          }
          start = i;
          if (nums.length - start < result) {
            // return result
            break
          };
        }
      }
      return str.slice(start1, end1)
    }
    console.log(getMax(str));


    ```
Edit this page
最近更新: 2025/6/27 02:24
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人