1248. Count Number of Nice Subarrays Medium

@problem@discussion
#Array#Hash Table#Math#Sliding Window



1/**
2 * [1248] Count Number of Nice Subarrays
3 *
4 * Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
5 * 
6 * Return the number of nice sub-arrays.
7 * 
8 *  
9 * Example 1:
10 * 
11 * 
12 * Input: nums = [1,1,2,1,1], k = 3
13 * Output: 2
14 * Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
15 * 
16 * 
17 * Example 2:
18 * 
19 * 
20 * Input: nums = [2,4,6], k = 1
21 * Output: 0
22 * Explanation: There is no odd numbers in the array.
23 * 
24 * 
25 * Example 3:
26 * 
27 * 
28 * Input: nums = [2,2,2,1,2,2,1,2,2,2], k = 2
29 * Output: 16
30 * 
31 * 
32 *  
33 * Constraints:
34 * 
35 * 
36 * 	1 <= nums.length <= 50000
37 * 	1 <= nums[i] <= 10^5
38 * 	1 <= k <= nums.length
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/count-number-of-nice-subarrays/
44// discuss: https://leetcode.com/problems/count-number-of-nice-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn number_of_subarrays(nums: Vec<i32>, k: i32) -> i32 {
50        
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_1248() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.