[LeetCode]最大连续1的个数

版权声明:本文为本人原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37316917/article/details/87888373

题目

 

代码 

class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int length=0;
        int maxLength=0;
        for(int i=0;i<nums.size();i++)
        {
            if(nums[i]==0)
                length=0;
            else
                length++;
            if(length>maxLength)
                maxLength=length;
        }
        return maxLength;
    }
};

猜你喜欢

转载自blog.csdn.net/m0_37316917/article/details/87888373