class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int nMax = 0;
int ntemp = 0;
for(int n = 0; n < nums.size(); n++)
{
if(nums[n] == 1)
{
ntemp ++;
}
else
{
if(nMax < ntemp)
{
nMax = ntemp;
}
ntemp = 0;
if(nMax >= (nums.size() - n))
{
break;
}
}
}
if(nMax < ntemp)
{
nMax = ntemp;
}
return nMax;
}
};
相关文章
- 03-07【LeetCode】1004. Max Consecutive Ones III 解题报告(C++)
- 03-07【leetcode】1004. Max Consecutive Ones III
- 03-07Non-negative Integers without Consecutive Ones
- 03-07485. Max Consecutive Ones
- 03-07485. Max Consecutive Ones
- 03-07485. Max Consecutive Ones
- 03-071004. Max Consecutive Ones III
- 03-07[LeetCode&Python] Problem 485. Max Consecutive Ones
- 03-07leetcode: 600. Non-negative Integers without Consecutive Ones
- 03-07[leetcode]Max Consecutive Ones II