非常简单,注意边界

class Solution:
    def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
        maxCnt = 0
        cnt = 0
        for i in range(len(nums)):
            if nums[i] == 1:
                cnt += 1
                if cnt > maxCnt:
                    maxCnt = cnt
            else:
                cnt = 0
        return maxCnt

  

相关文章:

  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-08
  • 2021-10-12
猜你喜欢
  • 2021-10-08
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案