1004.最大连续1的个数III
方法:滑动窗口
class Solution {
public int longestOnes(int[] nums, int k) {
int left = 0,right = 0,zero = 0,res = 0;
while(right < nums.length){
if(nums[right]==0){
zero++;
}
while(zero > k){
if(nums[left] == 0){
zero--;
}
left++;
}
res = Math.max(res,right - left + 1);
right++;
}
return res;
}
}