Count Number of Nice Subarrays LeetCode solution in Rust
1impl Solution {2pub fn number_of_subarrays(nums: Vec<i32>, k: i32) -> i32 {3let mut total = 0;4let mut odd = 0;5let mut count = 0;67let mut j = 0;8let is_odd = |x| x % 2 == 1;910for &num in nums.iter() {11if is_odd(num) {12odd += 1;13count = 0;14}1516while odd == k {17if is_odd(nums[j]) {18odd -= 1;19}20count += 1;21j += 1;22}23total += count;24}2526total as i3227}28}