[leetcode]485. Max Consecutive Ones
Analysis
生而为人要善良啊~—— [ummmm~]
Given a binary array, find the maximum number of consecutive 1s in this array.
寻找最大长度的连续1。
Implement
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int res = 0;
int cnt = 0;
for(auto num:nums){
if(num == 1)
cnt++;
else
cnt = 0;
res = max(cnt, res);
}
return res;
}
};