当前位置:网站首页>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;
}
边栏推荐
- Explanation of service registration and discovery API of Nacos series
- Use of mongodb
- NVIDIA Jetson nano/xavier NX capacity expansion tutorial
- 19 calling subprocess (callactivity) of a flowable task
- How MySQL optimizes the use of joint index ABC
- ffmpeg 下载后缀为.m3u8的视频文件
- Randomly fetch data from the list
- Django uses redis to store sessions starting from 0
- Three paradigms of MySQL
- Let's talk about how ArrayList is dynamically resized and what kind of mechanism is it?
猜你喜欢

3. Postman easy to use

The reason why the process cannot be shut down after a spark job is executed and the solution

Function and application scenario of field setaccessible() method

NVIDIA Jetson Nano/Xavier NX 扩容教程

Missing tag identification in cots RFID systems: bringing the gap between theory and Practice

Difference between deviation and variance in deep learning

10 signalstartevent and signalcatchingevent of flowable signal events

OpenGL马赛克(八)

13 cancelendevent of a flowable end event and compensationthrowing of a compensation event

Hainan University Postgraduate Entrance Examination electronic information (085400) landing experience
随机推荐
890. Find and Replace Pattern
Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio
Parallelgateway and exclusivegateway of 14 gateways
powershell优化之一:提示符美化
Solve the problem of garbled code in the MySQL execution SQL script database in docker (no need to rebuild the container)
C calls the API and parses the returned JSON string
Django uploads local binaries to the database filefield field
= = relation between int and integer
Web site learning and sorting
MongoDB 多字段聚合Group by
JS output uincode code
Byte buddy print execution time and method link tracking
Function and application scenario of field setaccessible() method
19 calling subprocess (callactivity) of a flowable task
Hump naming and underlining
18 flowable task manualtask and receivetask
Misunderstanding of tongweb due to ease of use
1 Introduction to drools rule engine (usage scenarios and advantages)
ArrayList loop removes the pit encountered
NVIDIA Jetson nano/xavier NX capacity expansion tutorial