485. Max Consecutive Ones
来源:互联网 发布:广州恒大淘宝足球俱乐部票务商城 编辑:程序博客网 时间:2024/06/05 05:21
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 max = 0,flag=0,temp = 0; for(int i = 0;i<nums.size();i++){ if(nums[i]==1){ temp++; }else if(nums[i]==0){ if(temp>max) max = temp; temp =0; } } if(temp>max) max = temp; 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
- [容斥] BZOJ 4762 最小集合
- 单源最短路问题(dijkstra算法)
- 用SDL显示不同的风格文字
- javascript引擎、编辑器、作用域之间的合作
- A+B for Input-Output Practice (IV)
- 485. Max Consecutive Ones
- JavaSE.jdk安装步骤
- selenium使用小瓜子
- HTML布局
- bzoj 4128: Matrix BSGS+矩阵乘法
- 最小生成树
- 多“维”优化——前端高并发策略的更深层思考
- php小工具类php下将XML转换为数组
- 写了一个计时器