simple c++ recursive solution


  • 0
    B
        int findMaxConsecutiveOnes(vector<int> &nums, int start = 0) {
            auto it = find(nums.begin() + start, nums.end(), 0);
            int ones = it - nums.begin() - start;
            if (it == nums.end()) return ones;
            else {
                return max(ones, findMaxConsecutiveOnes(nums, (it - nums.begin() + 1)));
            }
        }```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.