LeetCode 485 Max Consecutive Ones 解题报告
题目要求
Given a binary array, find the maximum number of consecutive 1s in this array.
题目分析及思路
给定一个01数组,要求找到这个数组中连续1的最大长度。可以考虑0的位置,结合数组切片,循环进行。要记得把最后数组的长度加上。
python代码
class Solution:
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
if len(set(nums)) == 1 and nums[0] == 1:
return len(nums)
ones = []
while 0 in nums:
zero = nums.index(0)
ones.append(zero)
nums = nums[zero+1:]
ones.append(len(nums))
return max(ones)
LeetCode 485 Max Consecutive Ones 解题报告的更多相关文章
- 【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, ...
- 8. leetcode 485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- (双指针) leetcode 485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- LeetCode: 485 Max Consecutive Ones(easy)
题目: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: ...
- [LeetCode]485. Max Consecutive Ones 找到最大的连续的1的个数
题目描述 输入只有0和1的数组(长度为正整数,且<10000),找到最大的连续1的个数 比如[1,1,0,1,1,1],输出3 思路 遍历数组,统计当前连续个数curCount和最大连续值max ...
- 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告(Python)
[LeetCode]659. Split Array into Consecutive Subsequences 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...
- 【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 ...
随机推荐
- java中job运行时间
long startTime=System.currentTimeMillis();//记录开始时间 method();//此处为你调用的方法 long endTime=System.currentT ...
- layui.laytpl中js方法书写及调用:去除html标签
<script type="text/html" id="conTpl"> {{# var delhtml = function(str) { ...
- 【iCore4 双核心板_FPGA】例程六:触发器实验——触发器的使用
实验现象: 按下按键,绿色led亮灭交互: //--------------------module_rst_n---------------------------// module trigger ...
- 非root用户如何使用docker命令
docker命令默认只能root使用的,但我们可以赋权给其他用户,使用时先照常新建用户: [root@10 ~]# useradd docker [root@10 ~]# passwd docker ...
- Git 更新操作
修改现有函数 Tom 执行克隆操作后,看到新的文件string.c,他想知道这个文件到存储库?目的是什么?于是,他执行 git 日志命令. [tom@CentOS ~]$ git clone gitu ...
- php 无限分类 树形数据 格式化
测试demo ------------------------------------------------------------------------------------ <?php ...
- Fedora 21 安装 Bumblebee with the NVIDIA proprietary drivers
最新文章:Virson's Blog 参考Fedora Wiki:http://fedoraproject.org/wiki/Bumblebee#Fedora_21
- 教程:Spagobi开源BI系统 Console报表设计教程
Console Designer 1 Console Designer Console Designer 1.1 Introduction 1.2 Dataset Tab 1.3 Summary Pa ...
- MSM8953 audio dts 代码跟踪
跟一下msm8953音频的dts. msm8953-audio-mtp.dtsi &int_codec { status = "okay"; qcom,model = &q ...
- windows 注册表讲解
注册表存储结构: 整个注册表内容主要由项(键).值(键值)构成.(通过regedit命令打开注册表) 5个根键: HKEY_CLASSES_ROOT (缩写HKCR) HKEY_CURRENT_ ...