问题描述

给定一个二进制数组, 计算其中最大连续1的个数。

示例 1:

输入: [1,1,0,1,1,1]
输出: 3
解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3.

注意:

  • 输入的数组只包含 01
  • 输入数组的长度是正整数,且不超过 10,000。

解决方案

class Solution:
    def findMaxConsecutiveOnes(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        count = 0
        max_count =0
        for i in nums:
            if i == 1:
                count += 1
            else:
                max_count = max(count,max_count)
                count = 0
        return max(count,max_count)

相关文章:

  • 2022-12-23
  • 2021-07-21
  • 2021-11-14
  • 2021-09-11
  • 2021-04-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
猜你喜欢
  • 2021-09-28
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2021-12-26
相关资源
相似解决方案