class Solution {
public int longestOnes(int[] nums, int k) {
int left = 0, right = 0, result = 0;
while(right < nums.length){
if(nums[right] == 0){
if(k == 0){
// 若nums[left]一直是1,那么还要往右一个
while(nums[left] == 1) ++left;
++left;
}else{
--k;
}
}
result = Math.max(result, ++right - left);
}
return result;
}
}