当前位置:网站首页>leetcode:485.最大连续 1 的个数
leetcode:485.最大连续 1 的个数
2022-07-31 13:41:00 【心软且酷丶】
难度:简单
给定一个二进制数组
nums
, 计算其中最大连续1
的个数。示例 1:
输入:nums = [1,1,0,1,1,1] 输出:3 解释:开头的两位和最后的三位都是连续 1 ,所以最大连续 1 的个数是 3.示例 2:
输入:nums = [1,0,1,1,0,1] 输出:2提示:
1 <= nums.length <= 10ⁿ
- n = 5
nums[i]
不是0
就是1.
题解:
class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: Count = 0 Max = 0 for i in nums: if i == 1: Count += 1 Max = max(Max,Count) if i == 0: Count = 0 return Max
边栏推荐
猜你喜欢
Open Inventor 10.12 重大改进--和谐版
Reasons and solutions for Invalid bound statement (not found)
networkx绘制度分布
IDEA找不到Database解决方法
ADS communicate with c #
代码随想录笔记_哈希_454四数相加II
Hard disk partition, expand disk C, no reshipment system, not heavy D dish of software full tutorial.
Detailed explanation of network protocols and related technologies
Edge Cloud Explained in Simple Depth | 4. Lifecycle Management
网络协议及相关技术详解
随机推荐
The latest complete code: Incremental training using the word2vec pre-training model (two loading methods corresponding to two saving methods) applicable to various versions of gensim
Buffer 与 拥塞控制
多智能体协同控制研究中光学动作捕捉与UWB定位技术比较
0X7FFFFFFF,0X80000000「建议收藏」
Samba 远程命令执行漏洞(CVE-2017-7494)
Hard disk partition, expand disk C, no reshipment system, not heavy D dish of software full tutorial.
C# List Usage List Introduction
JSP response对象简介说明
Flutter keyboard visibility
3.爬虫之Scrapy框架1安装与使用
基于高阶微分器的无模型滑模控制器及其在自动电压调节器中的应用
【蓝桥杯选拔赛真题46】Scratch磁铁游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
网络协议及相关技术详解
Error IDEA Terminated with exit code 1
报错:npm ERR code EPERM
selenium被反爬了怎么办?
Introduction to the PartImageNet Semantic Part Segmentation dataset
MATLAB | 我也做了一套绘图配色可视化模板
ICML2022 | 面向自监督图表示学习的全粒度自语义传播
C语言基础练(九九乘法表)与打印不同星号图案