Appearance
1004 最大连续1 个数
code
javascript
/**
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
var longestOnes = function(nums, k) {
let ind_left = 0;
let ind_right = 0;
let count = 0;
let max = 0;
while(ind_right < nums.length){
if(nums[ind_right] === 0){
count++;
}
while(count > k){
if(nums[ind_left] === 0){
count--;
}
ind_left++;
}
max = Math.max(max, ind_right - ind_left + 1);
ind_right++;
}
return max;
};总结
- 好像跟之前做过那个差不多,我也不知道区别是啥