Max Consecutive Ones III (for E5 :)
This is Max Consecutive Ones III, LC 1004 :)
The other question was - Get Minimum Round Trip Cost (: for E4 && E5 :) --> Click me, I ma a link~
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.
Complete the function longestOnes in the editor.
longestOnes has the following parameters:
- 1.
int[] nums: a binary array - 2.
int k: the maximum number of 0's that can be flipped
Returns
int: the maximum number of consecutive 1's
1Example 1
[1,1,1,0,0,1,1,1,1,1,1]
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
2Example 2
[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
Constraints
Limits and guarantees your solution can rely on.
1 <= nums.length <= 10^5nums[i]is either 0 or 1.0 <= k <= nums.length