Skip to content

485. 最大连续1的个数 ​

  • 题号:485
  • 来源:LeetCode
  • 难度:简单
  • 标签:数组 模拟
  • 语言:TypeScript
  • 解法:1 个
  • 作者:lmliheng
  • 最近更新:2026-09-27

TypeScript · O(n) 时间 · O(n) 空间 · 更新于 2026-09-27

拼成字符串按0切分,打印各段长度

typescript
/**
 * @difficulty easy
 * @tags 数组,模拟
 * @time O(n)
 * @space O(n)
 * @note 拼成字符串按0切分,打印各段长度
 * @485. 最大连续1的个数
 */
let nums = [1, 1, 0, 1, 1, 1]
console.log(nums.join('').split('0').map(item => item.length))

源码:ts/leetcode/485. 最大连续1的个数.ts


在 GitHub 上查看题目所在目录:lmliheng/algorithm