485. Max Consecutive Ones
来源:互联网 发布:linux解压tar包 编辑:程序博客网 时间:2024/06/05 05:28
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
and1
. - The length of input array is a positive integer and will not exceed 10,000
class Solution {public: int findMaxConsecutiveOnes(vector<int>& nums) { int sum = 0; int max = 0; for(int i = 0; i < nums.size(); ++i){ if(nums[i] == 1){ sum++; if(sum > max){ max = sum; } }else{ sum = 0; } } return max; }};
阅读全文
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
- 从零开始学_JavaScript_系列(63)——class(4)静态方法和new.target
- 设计模式之工厂方法模式
- mysql中char与varchar的区别分析
- YYWebImage使用
- Junit单元测试学习笔记三
- 485. Max Consecutive Ones
- oracle使用笔记
- 关于frameworks层源码编译
- Nio(九)ServerSocketChannel
- SQL中常用模糊查询的四种匹配模式&&正则表达式
- 上下拉电阻-RS485(三)
- Kubernetes学习总结(1)——Kubernetes入门简介
- 某Python进程出现线程卡住情况的排查记录
- web,java,poi导出excel