485. Max Consecutive Ones

Easy

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 0 and 1.
  • 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的更多相关文章

  1. 【leetcode】485. Max Consecutive Ones

    problem 485. Max Consecutive Ones solution1: class Solution { public: int findMaxConsecutiveOnes(vec ...

  2. [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 ...

  3. 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 ...

  4. LeetCode——Max Consecutive Ones

    LeetCode--Max Consecutive Ones Question Given a binary array, find the maximum number of consecutive ...

  5. 485. Max Consecutive Ones最长的连续1的个数

    [抄题]: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Inpu ...

  6. 485. Max Consecutive Ones【easy】

    485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in t ...

  7. LeetCode Max Consecutive Ones II

    原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-ii/ 题目: Given a binary array, find the ma ...

  8. 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 ...

  9. 485. Max Consecutive Ones@python

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

随机推荐

  1. DES加密算法介绍(含例子)

    http://www.hankcs.com/security/des-algorithm-illustrated.html DES(Data Encryption Standard)算法是世界上最常用 ...

  2. vue全家桶面试

    vue:主要Vue ​ vue-router:关于路由方面的配置 ​ vuex:数据共享和缓存用 ​ vue-resource:于后台交互用(现在改为axios 但是axios不是Vue里面的东西) ...

  3. GC线程是不是守护线程

    是 线程的话分为守护线程和非守护线程(即用户线程) 只要当前JVM实例中尚存在任何一个非守护线程没有结束,守护线程就全部工作; 只有当最后一个非守护线程结束时,守护线程随着JVM一同结束工作,守护线程 ...

  4. Mysql 日常

    Mysql 日常总结 做报表的时候经常会使用 if 来帮助统计 select count(if(key=1,1,NULL)) from atable where ... 当然,也支持选择 select ...

  5. JMeter基础【第六篇】JMeter5.1事务、检查点、集合点、思考时间、其余设置等

    JMeter5.1事务.检查点.集合点.思考时间.其余设置等

  6. read函数和write函数

    read 函数 inline int read() { ,f=; char c=getchar(); ; c=getchar();} +c-'; c=getchar();} return f*x; } ...

  7. datetime.now()提示没有now方法

    py3.6 导入方法是 from datetime import datetime 在使用datetime.now()的时候报错,说没有now 在保存module的create_time字段的时候,提 ...

  8. JavaScript == 与 === 区别

    1.对于 string.number 等基础类型,== 和 === 是有区别的 a)不同类型间比较,== 之比较 "转化成同一类型后的值" 看 "值" 是否相等 ...

  9. SDOI 2014 向量集

    [SDOI2014]向量集 题目描述 维护一个向量集合,在线支持以下操作: - "A x y (|x|,|y| < =10^8)":加入向量(x,y); - " Q ...

  10. 【LG2839】[国家集训队]middle

    [LG2839][国家集训队]middle 题面 洛谷 题解 按照求中位数的套路,我们二分答案\(mid\),将大于等于\(mid\)的数设为\(1\),否则为\(-1\). 若一个区间和大于等于\( ...