Posted on

Description

Submission

class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        nums.insert(nums.begin(), 0);
        nums.push_back(0);

        int beg = 0, ret = 0;
        for(int i = 0; i < nums.size() - 1; ++i) {
            if(nums[i] == 0 && nums[i+1] == 1) beg = i;
            if(nums[i] == 1 && nums[i+1] == 0) {
                ret = max(ret, i - beg);
            }
            
        }
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *