当前位置:网站首页>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
0and1. - 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;
}
边栏推荐
- A simple recursion problem of linked list
- AUTOSAR actual combat tutorial pdf version
- Use of mongodb
- About Evaluation Metrics
- Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio
- 13 cancelendevent of a flowable end event and compensationthrowing of a compensation event
- Leetcode judge subsequence simple
- The reason why the process cannot be shut down after a spark job is executed and the solution
- Building a stand-alone version of Nacos series
- Unity游戏优化[第二版]学习记录6
猜你喜欢

powershell优化之一:提示符美化

Nacos series registry principle and source code analysis

Shardingsphere JDBC exception: no table route info

OpenGL馬賽克(八)

How to Algorithm Evaluation Methods

Mongodb multi field aggregation group by

Getclassloader() returns null, getclassloader() gets null

ffmpeg 下载后缀为.m3u8的视频文件
![[China & some provinces and cities] JSON file for offline map visualization](/img/ea/0c552e1e133f693b9902c54c2e09c8.jpg)
[China & some provinces and cities] JSON file for offline map visualization

2021.9.30学习日志-postman
随机推荐
Bicolor case
Calculate the number of days between two times (supports cross month and cross year)
19 calling subprocess (callactivity) of a flowable task
How to view tongweb logs correctly?
C calls the API and parses the returned JSON string
Web site learning and sorting
About Evaluation Metrics
Exception after repeated application redeployment on tongweb: application instance has been stopped already or outofmemoryerror:metaspace
High availability of Nacos series
MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
Sentinel series introduction to service flow restriction
【自动化测试】Cypress手册
NVIDIA Jetson Nano/Xavier NX 扩容教程
Input a number and output each digit from high to low
Service fusing and degradation of Note Series
Service architecture diagram of Nacos series
The 13th week of the second semester of sophomore year
MySQL fuzzy query and sorting by matching degree
Interrupt processing
10 signalstartevent and signalcatchingevent of flowable signal events