Given a binary array, find the maximum number of consecutive 1s in this array.

Example 1:

Input: [1,1,0,1,1,1]
Output: 3
Explanation: 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 and 1.
  • The length of input array is a positive integer and will not exceed 10,000
 
class Solution(object):
def findMaxConsecutiveOnes(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
maxn=0
cur=0 for i in nums:
if i==1:
cur+=1
else:
if cur>maxn:
maxn=cur
cur=0 if cur>maxn:
maxn=cur return maxn

  

[LeetCode&Python] Problem 485. Max Consecutive Ones的更多相关文章

  1. [LeetCode&Python] Problem 807. Max Increase to Keep City Skyline

    In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located the ...

  2. LeetCode Array Easy 485. Max Consecutive Ones

    Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1 ...

  3. 【leetcode】485. Max Consecutive Ones

    problem 485. Max Consecutive Ones solution1: class Solution { public: int findMaxConsecutiveOnes(vec ...

  4. 485. Max Consecutive Ones - LeetCode

    Question 485. Max Consecutive Ones Solution 题目大意:给一个数组,取连续1的最大长度 思路:遍历数组,连续1就加1,取最大 Java实现: public i ...

  5. 485. Max Consecutive Ones【easy】

    485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in t ...

  6. 485. Max Consecutive Ones@python

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

  7. 485. Max Consecutive Ones最长的连续1的个数

    [抄题]: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Inpu ...

  8. 【LeetCode】485. Max Consecutive Ones 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...

  9. LeetCode 485. Max Consecutive Ones (最长连续1)

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

随机推荐

  1. PowerShell使用教程

    一.说明 1.1 背景说明 个人对PowerShell也不是很熟悉,开始的时候就突然看到开始菜单中多了个叫PowerShell的文件夹,后来一点就看到某个教程视频说PowerShell很厉害但也没怎么 ...

  2. weblogic启动比一般机器慢原因

    weblogic启动慢一般先看setDomainEnv.sh中分配给JVM的内存大小,如果分配足够(没部应用一般也要1G以上)那么再用free -g看本机剩余内存是否充足.如果都没问题还是比一般机器启 ...

  3. AMR文件结构

    转自:http://blog.csdn.net/dinggo/article/details/1966444 https://blog.csdn.net/wlsfling/article/detail ...

  4. MyEclipse常用设置和快捷键

    Java快捷键 1.注释快捷键 先敲/  再敲两个**     Enter 回车 2.system.out.println(); 常用设置 [子类继承父类] [编码字体设置] 删除当前行:ctrl+d ...

  5. 微信授权(Net Mvc)

    项目结构 WeiXinController.cs using System; using System.Collections.Generic; using System.Linq; using Sy ...

  6. eclipse package视图和navigator视图的区别

    package视图是适合开发的视图,因为开发时我们只关注源文件,并不关注编译后的二进制文,所有在该视图中存放二进制文件的classes文件被隐藏了,而navigator视图,就是项目在工作空间中存放的 ...

  7. Turing equation

    Turing equation 时间限制: 1 Sec 内存限制: 128 MB 题目描述 The fight goes on, whether to store numbers starting w ...

  8. Android知识补充(Android学习笔记)

    Android知识补充 ●国际化 所谓的国际化,就是指软件在开发时就应该具备支持多种语言和地区的功能,也就是说开发的软件能同时应对不同国家和地区的用户访问,并针对不同国家和地区的用户,提供相应的.符合 ...

  9. VSTO:使用C#开发Excel、Word【5】

    <Visual Studio Tools for Office: Using C# with Excel, Word, Outlook, and InfoPath >——By Eric C ...

  10. Cracking The Coding Interview 9.3

    //Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log ...