Loading

[LeetCode]最大连续1的个数

题目

 

代码 

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;
    }
};

 

posted @ 2019-02-23 09:14  李正浩  阅读(253)  评论(0编辑  收藏  举报