当前位置:网站首页>Leetcode- number of maximum consecutive ones - simple
Leetcode- number of maximum consecutive ones - simple
2022-06-13 05:49:00 【AnWenRen】
title :485 Maximum continuous 1 The number of - Simple
subject
Given a binary array , Calculate the maximum continuity 1 The number of .
Example
Input :[1,1,0,1,1,1]
Output :3
explain : The first two digits and the last three digits are consecutive 1 , So the greatest continuity 1 The number of is 3.
Tips
- The input array contains only
0
and1
. - The length of the input array is a positive integer , And no more than 10,000.
Code Java
public int findMaxConsecutiveOnes(int[] nums) {
int result = 0;
int j = -1;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0) {
if (result < i - j - 1)
result = i - j - 1;
j = i;
}
}
if (result < nums.length - j)
result = nums.length - j - 1;
return result;
}
边栏推荐
- OpenGL mosaic (VIII)
- How to Algorithm Evaluation Methods
- Nacos series registry principle and source code analysis
- Django uses redis to store sessions starting from 0
- Shardingsphere JDBC < bind table > avoid join Cartesian product
- Quartz basic use
- Comment procéder à l'évaluation des algorithmes
- Hump naming and underlining
- How to set the import / export template to global text format according to the framework = (solve the problem of scientific counting)
- AUTOSAR actual combat tutorial pdf version
猜你喜欢
How slow is the application system on tongweb? How dead is it?
Building a stand-alone version of Nacos series
Service architecture diagram of Nacos series
How to Algorithm Evaluation Methods
The reason why the process cannot be shut down after a spark job is executed and the solution
C calls the API and parses the returned JSON string
ffmpeg 下载后缀为.m3u8的视频文件
JS output uincode code
Source code analysis of ArrayList
为什么那么多人讨厌A-Spice
随机推荐
AUTOSAR actual combat tutorial pdf version
MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
Hainan University Postgraduate Entrance Examination electronic information (085400) landing experience
Exception after repeated application redeployment on tongweb: application instance has been stopped already or outofmemoryerror:metaspace
2021.9.29学习日志-MIME类型
【自动化测试】Cypress手册
About Evaluation Metrics
Current limiting and fusing of gateway gateway in Spirng cloud
9. Errorstartevent and errorboundaryevent of error events
Leetcode judge subsequence simple
Pychart encountered time zone problem when connecting to MySQL timezone
Sentinel series introduction to service flow restriction
Four shardingsphere JDBC sharding strategies
Concurrent programming -- what is threading?
About the solution of pychart that cannot be opened by double clicking
Power of leetcode-4 - simple
NVIDIA Jetson Nano/Xavier NX 扩容教程
@Detailed explanation of propertysource usage method and operation principle mechanism
MySQL fuzzy query and sorting by matching degree
Nacos series registry principle and source code analysis