# [LeetCode] Max Consecutive Ones 最大连续1的个数

+关注继续查看

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

class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int res = 0, cnt = 0;
for (int num : nums) {
cnt = (num == 0) ? 0 : cnt + 1;
res = max(res, cnt);
}
return res;
}
};

class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int res = 0, sum = 0;
for (int num : nums) {
sum = (sum + num) * num;
res = max(res, sum);
}
return res;
}
};

Hive Tunning（二）优化存储
《Hive Tunning》读后小记第二篇——Hive Tunning（二）优化存储。
1232 0
Hive之存储格式
Hive之存储格式
2285 0
windows c/c++ 代码运行时间，毫秒级
#pragma once /* //计算代码段运行时间的类 // */ #include #ifndef ComputeTime_h #define ComputeTime_h class ComputeTime { private: int Initial...
678 0

899 0
Atom + activate-power-mode震屏插件Windows7下安装
802 0
c函数习记
1,user groups 篇幅 the length of an article; 　　fgetgrent(从指定的文件来读取组格式) 　　相关related functions;fgetpwent 　　headers files includes: 　　　　#include 　　　　...
428 0

3224 0
ReactNative0.63正式版发布：LogBox
ReactNative0.63正式版发布：LogBox
0 0
【网络安全篇】--HTML基础（预计学习时间：30分钟）从此以后不迷糊~
🏆今日学习目标： 🍀学习HTML基础 ✅创作者：贤鱼
0 0
%C和%S区别
%C和%S区别
0 0
+关注