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

分析:计算1连续出现的最大次数。

思路:遍历统计次数,记录下连续出现的次数即可。

JAVA CODE

class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int times = 0, maxTimes = 0;
for(int i = 0; i < nums.length; i++){
if(nums[i] == 0){
maxTimes = maxTimes > times ? maxTimes : times;
times = 0;
}else{
times++;
}
}
return maxTimes = maxTimes > times ? maxTimes : times;
}
}
 

Max Consecutive Ones的更多相关文章

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

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

  3. 【leetcode】485. Max Consecutive Ones

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

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

  10. LeetCode_485. Max Consecutive Ones

    485. Max Consecutive Ones Easy Given a binary array, find the maximum number of consecutive 1s in th ...

随机推荐

  1. jenkins到底如何拉取代码 如何部署的

    tips:jenkins通过配置,将之前编译.打包.上传.部署到Tomcat中的过程交由jenkins,jenkins通过指定的代码地址url,将代码拉取到其jenkins的安装位置,进行编译.打包和 ...

  2. 【ASP.NET MVC】View与Controller之间传递数据

    1   概述 本篇文章主要从操作上简要分析Controller<=>View之间相互传值,关于页面之间传值,如果感兴趣,可参考我另外一篇文章ASP.NET 页面之间传值的几种方式 . Co ...

  3. Webservice优缺点总结

    优点: 1 .采用xml支持跨平台远程调用. 2.基于http的soap协议,可跨越防火墙. (因为SOAP一般使用HTTP协议,而服务器的这个协议一般都是开放的,而且是可以穿过防火墙的) 3.支持面 ...

  4. WAF防火墙介绍

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt187 在互联网应用高速发展的同时,承载Web信息系统的Web服务器也面临着巨 ...

  5. 【C#多线程编程实战笔记】一、 线程基础

    创建线程 Thread :所执行的方法不能有参数. class Program { static void Main(string[] args) { Console.WriteLine(" ...

  6. java基于注解的redis自动缓存实现

    目的: 对于查询接口所得到的数据,只需要配置注解,就自动存入redis!此后一定时间内,都从redis中获取数据,从而减轻数据库压力. 示例: package com.itliucheng.biz; ...

  7. 在Centos7x上部署docker

    docker只支持CentOS7.x系统,所以近期根据docker官网指南自己搭建了一套,供大家参考. 1.部署Centos7.x系统,查看系统版本. 2.执行 sudo yum update 更新到 ...

  8. 转:JDK中的URLConnection参数详解

    针对JDK中的URLConnection连接Servlet的问题,网上有虽然有所涉及,但是只是说明了某一个或几个问题,是以FAQ的方式来解决的,而且比较零散,现在对这个类的使用就本人在项目中的使用经验 ...

  9. 【2017集美大学1412软工实践_助教博客】团队作业9——测试与发布(Beta版本)

    题目 团队作业9--测试与发布(Beta版本)(http://www.cnblogs.com/happyzm/p/6917253.html) 团队作业9-1 测试与发布成绩 分值 1 0.5 0.5 ...

  10. 201521123082《Java程序设计》第2周学习总结

    201521123082<Java程序设计>第2周学习总结 标签(空格分隔): Java 1.本周学习总结 巩固了类型转换的相关细节 初步认识了类和对象,使用Java撰写程序几乎都在使用对 ...