题目描述
You are given array nums of n length 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:
Input:
n = 11
nums = [1,1,1,0,0,0,1,1,1,1,0]
k = 2
Output:
6
Explanation:
You can flip 2 0 and obtain [1,1,1,0,0,1,1,1,1,1,1]
Your Task:
You don't have to read input or print anything. Your task is to complete the function longestOnes() which takes the integer n and array nums and integer K as input and returns the longest ones which can be obtained after k flip.
Expected Time Complexity: O(n)
Expected Space Complexity: O(1)
Constraint:
1<=n<=10^{5}
0<=nums<=1
0<=k<=n
输入格式
见题面
输出格式
见题面
样例输入
n = 11
nums = [1,1,1,0,0,0,1,1,1,1,0]
k = 2
样例输出
6