python--leetcode485. Max Consecutive Ones
来源:互联网 发布:网络教育怎么 编辑:程序博客网 时间:2024/05/16 12:06
Given a binary array, find the maximum number of consecutive 1s in this array.
Example 1:
Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.
Note:
- The input array will only contain
0
and1
.
- The length of input array is a positive integer and will not exceed 10,000
这一题非常地简单啊....题目意思就是给你一个list,里面只有0或者1,求1连续的最大次数。
直接上代码吧,不需要讲解:
class Solution(object): def findMaxConsecutiveOnes(self, nums): """ :type nums: List[int] :rtype: int """ max=0 count=0 for i in range(len(nums)): if nums[i]==1: count+=1 if count>max: max=count if nums[i]==0: count=0 return maxs=Solution()print(s.findMaxConsecutiveOnes([0,1,1,1,0,1,1]))
阅读全文
1 0
- python--leetcode485. Max Consecutive Ones
- leetcode485: Max Consecutive Ones
- leetcode485~Max Consecutive Ones
- leetcode485. Max Consecutive Ones
- Leetcode485. Max Consecutive Ones
- leetcode485. Max Consecutive Ones
- Max Consecutive Ones---LeetCode485
- LeetCode485.Max Consecutive Ones题解
- leetcode485 Max Consecutive Ones Java
- LeetCode485:Max Consecutive Ones 解答
- LeetCode485. Max Consecutive Ones有你真好
- [leetcode: Python]485. Max Consecutive Ones
- 485. Max Consecutive Ones*
- 485. Max Consecutive Ones
- LEETCODE--Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 将任意三个数按从大到小输出
- 在Windows下同时安装Python2.x和Python3.x
- 逃离东北两整年
- 10.8
- 简单理解javascript中apply()和call()
- python--leetcode485. Max Consecutive Ones
- 二维码扫描
- 会话跟踪的多种方法
- 游戏小透明与Construct 2的初次邂逅
- 中缀表达式转为后缀表达式
- Rust: codewars的Molecule to atoms
- (M)Dynamic Programming:673. Number of Longest Increasing Subsequence
- 高通Qualcomm平台lk(light kernel)启动流程3——到高通lcm屏点亮
- 自定义view箭头绕圆环旋转