1004.最大连续1的个数Ⅲ
作者:互联网
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;
}
}
标签:result,right,nums,int,个数,++,连续,1004,left 来源: https://blog.csdn.net/Split_token/article/details/122707470