[LeetCode&Python] Problem 485. Max Consecutive Ones
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
and1
. - 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的更多相关文章
- [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 ...
- LeetCode Array Easy 485. Max Consecutive Ones
Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1 ...
- 【leetcode】485. Max Consecutive Ones
problem 485. Max Consecutive Ones solution1: class Solution { public: int findMaxConsecutiveOnes(vec ...
- 485. Max Consecutive Ones - LeetCode
Question 485. Max Consecutive Ones Solution 题目大意:给一个数组,取连续1的最大长度 思路:遍历数组,连续1就加1,取最大 Java实现: public i ...
- 485. Max Consecutive Ones【easy】
485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in t ...
- 485. Max Consecutive Ones@python
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- 485. Max Consecutive Ones最长的连续1的个数
[抄题]: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Inpu ...
- 【LeetCode】485. Max Consecutive Ones 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...
- LeetCode 485. Max Consecutive Ones (最长连续1)
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
随机推荐
- [LeetCode] 23. Merge k Sorted Lists ☆☆☆☆☆
转载:https://leetcode.windliang.cc/leetCode-23-Merge-k-Sorted-Lists.html 描述 Merge k sorted linked list ...
- python(6)之文件
一.读写文件 以追加文件内容(a).读(r).写(w),读写(r+)的形式打开文件: f = open('yesterday','a',encoding='utf-8')#文件句柄 #输出一行文件内容 ...
- Minimum supported Gradle version is 4.1. Current version is 2.14.1
Error:Minimum supported Gradle version is 4.1. Current version is 2.14.1. If using the gradle wrappe ...
- Uboot中汇编指令
LDR(load register)指令将内存内容加载入通用寄存器 ARM是RISC结构,数据从内存到CPU之间的移动只能通过L/S指令来完成,也就是ldr/str指令.比如想把数据从内存中某处读取到 ...
- 我在大学毕业后学习Linux系统的心得经验
扣着手指头一算,自己已经毕业快半年了,这半年莫名其妙进外包圈子溜达了一圈,有幸退的早还是正常干一些事情吧,外包终究不是太适合刚入社会的毕业生,今天想把自己的学习和工作经验写成一篇文章,希望能够帮助到正 ...
- OOP⑻
1.接口: 类 和 对象 对象 is a 类 例子: 小鸟 is a 动物 飞机 is a 交通工具 子弹 is a 武器 卫星 is a 通讯工具 问题? 01. 小鸟 飞机 子弹 卫星 虽然不是一 ...
- MariaDB的线程及连接
转自 linux公社 今天在这里介绍一下确认mariaDB(和MySQL一样)的链接数及线程数的方法.MariaDB和MySQL有什么不一样,现在还没有弄清楚. 这是减少数据库的负载,并能提高数据库运 ...
- Instruments leak黑魔法定位内存泄漏
leak是一款很赞的内存检查的工具,但在使用的过程中有点繁琐,至少有些底层的泄漏笔者还是不知道如何下手 下面介绍一下简单leak的使用: 首先你要确认你的target不会被拒绝,确保profile是d ...
- sqlalchemy 简介
#! /usr/bin/env python3 # -*- coding:utf-8 -*- #use SQLAlchemy #ORM:Object-Relational Mapping ,把关系数据 ...
- log4net 2.0.8 不支持core 数据库记录日志
经过反编译log4net 标准库的代码,原本有的数据库链接AdoNetAppender 在core里面引用的,没有掉了. 可能新版本会有.