485. Max Consecutive Ones
作者:互联网
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;
}
};
标签:nMax,ntemp,nums,int,Max,++,Ones,485,size 来源: https://blog.csdn.net/dw903632958/article/details/101268760