485. Max Consecutive Ones
来源:互联网 发布:网络接单平台 编辑:程序博客网 时间:2024/06/08 12:54
Given a binary array, find the maximum number of consecutive 1s in this array.
Example 1:
Input: [1,1,0,1,1,1]Output: 3Explanation: 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
public class Solution { public int findMaxConsecutiveOnes(int[] nums) { int result = 0; int temp = 0; for(int i=0;i<nums.length;i++){ if(nums[i]==0) temp =0; else{ temp += 1; result = Math.max(temp, result); } } return result; } }
阅读全文
0 0
- 485. Max Consecutive Ones*
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485.Max Consecutive Ones
- 深入理解react-redux
- POI excel 设置样式
- 关于junit断言
- 软件系统概要设计的三大要素
- 将两个并列的元素的属性设为inline-block的影响
- 485. Max Consecutive Ones
- 【dp】51nod 1154 回文串划分
- 如何实现js的map和filter函数
- 面对对象基础要点
- Java默认构造方法
- php7.1.8编译安装参数官方说明参考
- Java 泛型,你了解类型擦除吗?
- 结构体的内存对齐
- matlab 挂掉了,报的matlab licensing error -96