LeetCode_485. Max Consecutive Ones
485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.
Example 1:
Input: [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s.
The maximum number of consecutive 1s is 3.
Note:
- The input array will only contain
0and1. - The length of input array is a positive integer and will not exceed 10,000
package leetcode.easy;
public class MaxConsecutiveOnes {
public int findMaxConsecutiveOnes(int[] nums) {
int max = 0;
int curr_max = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 1) {
curr_max++;
if (curr_max > max) {
max = curr_max;
}
} else {
curr_max = 0;
}
}
return max;
}
@org.junit.Test
public void test() {
System.out.println(findMaxConsecutiveOnes(new int[] { 1, 1, 0, 1, 1, 1 }));
}
}
LeetCode_485. Max Consecutive Ones的更多相关文章
- 【leetcode】485. Max Consecutive Ones
problem 485. Max Consecutive Ones solution1: class Solution { public: int findMaxConsecutiveOnes(vec ...
- [LeetCode] Max Consecutive Ones II 最大连续1的个数之二
Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at mos ...
- Leetcode: Max Consecutive Ones II(unsolved locked problem)
Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at mos ...
- LeetCode——Max Consecutive Ones
LeetCode--Max Consecutive Ones Question Given a binary array, find the maximum number of consecutive ...
- 485. Max Consecutive Ones最长的连续1的个数
[抄题]: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Inpu ...
- 485. Max Consecutive Ones【easy】
485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in t ...
- LeetCode Max Consecutive Ones II
原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-ii/ 题目: Given a binary array, find the ma ...
- Flume启动报错[ERROR - org.apache.flume.sink.hdfs. Hit max consecutive under-replication rotations (30); will not continue rolling files under this path due to under-replication解决办法(图文详解)
前期博客 Flume自定义拦截器(Interceptors)或自带拦截器时的一些经验技巧总结(图文详解) 问题详情 -- ::, (SinkRunner-PollingRunner-Default ...
- 485. Max Consecutive Ones@python
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
随机推荐
- SpringBoot项目的测试类
1. package soundsystem; import static org.junit.Assert.*; import org.junit.Test; import org.junit.ru ...
- Spring @Autowired 注解 学习资料
Spring @Autowired 注解 学习资料 网址 Spring @Autowired 注解 https://wiki.jikexueyuan.com/project/spring/annota ...
- 第六次作业--static关键字、对象
##题目一 ##Computer package Train.Method.TeachDemo.Thread.Fuction; /** * 求n的阶乘算法 * @author 喵 * @date 20 ...
- 2019牛客国庆集训派对day3 买一送一
题目链接: 题意:有n个点,n-1条单向边,每个点都销售一类商品 问从点1开始走,买第一样商品类型为x,买第二样商品类型为y,问不同有序对<x,y>的数量 解法: col[i]表示这个点的 ...
- luogu_3645: 雅加达的摩天楼
雅加达的摩天楼 题意描述: 有\(N\)座摩天楼,从左到右依次编号为\(0\)到\(N-1\). 有\(M\)个信息传递员,编号依次为\(0\)到\(M-1\).编号为i的传递员最初在编号为\(B_i ...
- artillery强大灵活的负载测试套件
artillery是基于nodejs 编写的负载测试套件支持http&&socket.io&&websockets&&kinesis&& ...
- C++后端工程师需要看的书籍
C++基础书籍<C++ primer><深度探索C++对象模型><Effective C++><more effective C++><STL源码 ...
- linux命令之------rm命令
rm命令 1) 作用:用于删除一个文件或者目录: 2) -i:删除前逐一询问确认: 3) -f:即使原档案属性设为只读,亦直接删除,无需逐一确认: 4)-r:将目录及以下之档案亦逐一 ...
- Ubuntu 19.04 安装docker
配置国内源: deb https://mirrors.ustc.edu.cn/ubuntu/ disco main restricted universe multiverse deb https:/ ...
- list删除、集合遍历删除
public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<>(); li ...