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, ...
随机推荐
- reflow和repaint理解总结
repaint就是重绘,reflow就是回流 严重性: 在性能优先的前提下,reflow的性能消耗要比repaint的大. 体现: repaint是某个dom元素进行重绘,reflow是整个页面进行重 ...
- Java8新特性之forEach+Lambda 表达式遍历Map和List
这是Java8系列的第二篇,今天来说一下Java8中forEach的简单使用.我们使用对比的方式来看应该会看得更加清楚,更能理解: 一.遍历Map ============Java8之前的方式==== ...
- win10 系统运行加速方法
win10系统就是不太好用,很多功能我们硬件跟不上,会拖累系统运行速度,之前将win10优化了一部点,但是有些地方反而降低运行速度,因此需要关闭:1.磁盘的优化,这个说实话,可以自己来优化,没必要时刻 ...
- 2019 Nowcoder Multi-University Training Contest 1 H-XOR
由于每个元素贡献是线性的,那么等价于求每个元素出现在多少个异或和为$0$的子集内.因为是任意元素可以去异或,那么自然想到线性基.先对整个集合A求一遍线性基,设为$R$,假设$R$中元素个数为$r$,那 ...
- LeetCode 1091. Shortest Path in Binary Matrix
原题链接在这里:https://leetcode.com/problems/shortest-path-in-binary-matrix/ 题目: In an N by N square grid, ...
- BZOJ 5306: [Haoi2018]染色 二项式反演+NTT
给定长度为 $n$ 的序列, 每个位置都可以被染成 $m$ 种颜色中的某一种. 如果恰好出现了 $s$ 次的颜色有 $k$ 种, 则会产生 $w_{k}$ 的价值. 求对于所有可能的染色方案,获得价值 ...
- kuma kong 团队开发的可视化&&安全的service mesh
最近service mesh 的开源产品是越来越多了,好多团队都开源了自己的解决方案 maesh 最近kong 团队也开源了自己的service meshkuma 一张参考图 说明 kuma 没有基于 ...
- A`>G?~C009
A`>G?~C009 这场怎么才5题...看完猫的提交记录以为猫猫没写这场F A Multiple Array 直接做 B Tournament 直接树d C Division into Two ...
- linux高性能服务器编程 (五) --Linux网络编程基础api
第五章 Linux网络编程基础api 1.主机字节序和网络字节序 字节序是指整数在内存中保存的顺序.字节序分为大端字节序.小端字节序. 大端字节序:一个整数的高位字节数据存放在内存的低地址处.低位字节 ...
- [CMS]凡诺cms 2.1文件包含
0x01 简介 凡诺CMS下载链接:凡诺企业网站管理系统PHP 2.1 安装好了是这样的: 0x02 漏洞复现 在添加频道处上传附件: 根据网站根目录所在位置用../进行跨目录: 然后返回首页点击频道 ...