2024-05-06 21:30:18 +00:00
|
|
|
fn main() {
|
|
|
|
//dbg!(l(vec![1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0], 2));
|
|
|
|
dbg!(l(
|
|
|
|
vec![0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1],
|
|
|
|
3
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn l(nums: Vec<i32>, k: i32) -> i32 {
|
|
|
|
let len = nums.len() as i32;
|
|
|
|
let mut k = k;
|
|
|
|
let mut start: i32 = -1;
|
|
|
|
let nums = &nums;
|
|
|
|
|
2024-05-14 23:34:13 +00:00
|
|
|
for i in 0..len as usize {
|
|
|
|
if nums[i] == 0 {
|
2024-05-06 21:30:18 +00:00
|
|
|
k -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if k < 0 {
|
|
|
|
start += 1;
|
|
|
|
if nums[start as usize] == 0 {
|
|
|
|
k += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-14 23:34:13 +00:00
|
|
|
len - start - 1
|
2024-05-06 21:30:18 +00:00
|
|
|
}
|