Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
competitive-programming
code-generation
specification-generation
proof-generation
verification
rust
License:
File size: 796 Bytes
b2a430f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | impl Solution {
pub fn longest_subarray(nums: Vec<i32>) -> i32 {
let n = nums.len();
let mut left: usize = 0;
let mut zeros: i32 = 0;
let mut result: i32 = 0;
let mut right: usize = 0;
while right < n {
if nums[right] == 0 {
zeros = zeros + 1;
}
right = right + 1;
while zeros > 1 {
if nums[left] == 0 {
zeros = zeros - 1;
}
left = left + 1;
}
let window = if right > left {
(right - left) as i32 - 1
} else {
0
};
if window > result {
result = window;
}
}
result
}
}
|