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. Informatica学习:1、安装介质的获取与安装

    本文目标: 为方便学习Informatica工具,在个人电脑上部署Informatica Powercenter. 所用系统:win7 64位. Informatica安装包括服务器端.客户端安装两个 ...

  2. Windows上安装nvm--nodejs版本管理器

    nvm最新的下载地址 Node版本管理器--nvm,可以运行在多种操作系统上.nvm for windows 是使用go语言编写的软件. 我电脑使用的是Windows操作系统,所以我要记录下在此操作系 ...

  3. vim代码粘贴缩进混乱的问题[Linux]

    详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp76   直接在vim插入模式下粘贴: 直接粘贴,剪贴板上的每个字符都相当 ...

  4. django源码解析一(请求处理流程)

    1.我们都知道WSGI是一个规范,规范了server和application之间通信的一些约束,server端在监听到请求之后,会把请求转给application去处理,他们之间关联起来的桥梁是一个e ...

  5. [UWP]理解及扩展Expander

    ##1. 前言 最近在自定义Expander的样式,顺便看了看它的源码. Expander控件是一个ContentControl,它通过IsExpanded属性或者通过点击Header中的Toggle ...

  6. JS跨域请求 JSONP B/S全代码

    Ajax直接请求普通文件存在跨域无权限访问的问题,甭管你是静态页面.动态网页.web服务.WCF,只要是跨域请求,一律不准:Web页面上调用js文件时则不受是否跨域的影响(不仅如此,我们还发现凡是拥有 ...

  7. CCIE-MPLS VPN-实验手册(下卷)

    10:跨域的MPLS VPN (Option A) 10.1 实验拓扑 10.1 实验需求 a.       R1 R2 R3 组成P-NETWORK R1 R2 R3 位于AS 1,底层协议采用EI ...

  8. 转:H2 入门

    H2 Database做为轻量级的内嵌数据库,功能十分强大,而且运行时只需要一个jar包即可,下表是官网的描述: 更详细的对比见官网页面: http://www.h2database.com/html ...

  9. ionic项目ios真机部署(不需开发者账号)

    ionic项目ios真机部署(不需开发者账号) 安装ionic和cordova npm install -g ionic npm install -g cordova 创建一个新项目 ionic st ...

  10. 团队作业8——第二次项目冲刺(Beta阶段)--第五天

    一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 学号 成员 贡献比 201421123001 廖婷婷 15% 201421123002 翁珊 16% 201421123004 ...