1004. Max Consecutive Ones III
1004. Max Consecutive Ones III
Description
Difficulty: Medium
Related Topics: Array, Binary Search, Sliding Window, Prefix Sum
Given a binary array nums
and an integer k
, return the maximum number of consecutive 1
‘s in the array if you can flip at most k
0
‘s.
Example 1:
1 | Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2 |
Example 2:
1 | Input: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3 |
Constraints:
- 1 <= nums.length <= 105
nums[i]
is either0
or1
.0 <= k <= nums.length
Hints/Notes
- 2023/11/23
- sliding window
- 0x3F’s solution(checked)
Solution
Language: C++
1 | class Solution { |