0487. Max Consecutive Ones II
https://leetcode.com/problems/max-consecutive-ones-ii
Description
Given a binary array nums
, return the maximum number of consecutive 1
's in the array if you can flip at most one 0
.
Example 1:
Example 2:
Constraints:
1 <= nums.length <= 105
nums[i]
is either0
or1
.
Follow up: What if the input numbers come in one by one as an infinite stream? In other words, you can't store all numbers coming from the stream as it's too large to hold in memory. Could you solve it efficiently?
ac1: 2 pointers
ac2: sliding window
Last updated