2024/10/25 灵茶题单 不定长滑动窗口
This commit is contained in:
parent
db30196d08
commit
ec621a7da2
|
@ -0,0 +1,25 @@
|
||||||
|
package com.cool.ling_cha_mount.sliding_windows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/10/25/17:40
|
||||||
|
* @Description: 1004. 最大连续1的个数 III
|
||||||
|
* @Score 1656
|
||||||
|
*/
|
||||||
|
public class Num1004 {
|
||||||
|
public int longestOnes(int[] nums, int k) {
|
||||||
|
int zNum=0;
|
||||||
|
int res=0;
|
||||||
|
int left=0;
|
||||||
|
for(int i=0;i<nums.length;i++){
|
||||||
|
zNum+=(nums[i]^1);
|
||||||
|
while(zNum>k){
|
||||||
|
zNum-=(nums[left++]^1);
|
||||||
|
}
|
||||||
|
res=Math.max(res,i-left+1);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue