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 ...
随机推荐
- [转]bootstrap table 动态列数
原文地址:https://my.oschina.net/u/2356355/blog/1595563 据说bootstrap table非常好用,从入门教程中了解到它的以下主要功能: 由于固定表头意味 ...
- npm国内镜像
国内使用默认的源安装较慢,镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set registry h ...
- myeclipse创建hibernate工程
1.创建数据库: from blog http://www.cnblogs.com/zhaocundang/p/9061959.html 使用navicat mysql IDE: 创建数据库 book ...
- shell中的函数 shell中的数组 告警系统需求分析
- 通信原理之IP协议,ARP协议 (三)
把这三个协议放到一起学习是因为这三个协议处于同一层,ARP协议用来找到目标主机的Ethernet网卡Mac地址,IP则承载要发送的消息.数据链路层可以从ARP得到数据的传送信息,而从IP得到要传输的数 ...
- 显示windows的音频的输入输出设备
#include "stdafx.h" /************************音频的输入输出设备**************************/ #include ...
- ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
在开发一个python项目是,需要用到mysql,但是, 安装完mysql-python后import加载模块提示以下错误: ImportError: libmysqlclient_r.so.16: ...
- MFC打开文件选择框和多选框,保存文件夹的选择,保存文件路径的选择
CString defaultDir = "C:\\"; //默认打开的文件路径 CString fileName = ""; //默认打开的文件名 CStri ...
- perl 遍历指定目录下的所有文件,替换指定文本内容,返回受影响的文件路径
不会读取 影藏文件 main #!/usr/bin/perl use autodie; use utf8; use Encode qw(decode encode); if(@ARGV ne 3){ ...
- Flask web开发之路六
紧接着上篇文档,写模板继承和block,URL链接和加载静态文件 模板继承和block 项目结构 主app文件代码: from flask import Flask,render_template a ...