2348. Number of Zero-Filled Subarrays Medium
1/**
2 * [2348] Number of Zero-Filled Subarrays
3 *
4 * Given an integer array nums, return the number of subarrays filled with 0.
5 * A subarray is a contiguous non-empty sequence of elements within an array.
6 *
7 * Example 1:
8 *
9 * Input: nums = [1,3,0,0,2,0,0,4]
10 * Output: 6
11 * Explanation:
12 * There are 4 occurrences of [0] as a subarray.
13 * There are 2 occurrences of [0,0] as a subarray.
14 * There is no occurrence of a subarray with a size more than 2 filled with 0. Therefore, we return 6.
15 * Example 2:
16 *
17 * Input: nums = [0,0,0,2,0,0]
18 * Output: 9
19 * Explanation:
20 * There are 5 occurrences of [0] as a subarray.
21 * There are 3 occurrences of [0,0] as a subarray.
22 * There is 1 occurrence of [0,0,0] as a subarray.
23 * There is no occurrence of a subarray with a size more than 3 filled with 0. Therefore, we return 9.
24 *
25 * Example 3:
26 *
27 * Input: nums = [2,10,2019]
28 * Output: 0
29 * Explanation: There is no subarray filled with 0. Therefore, we return 0.
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= nums.length <= 10^5
35 * -10^9 <= nums[i] <= 10^9
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/number-of-zero-filled-subarrays/
41// discuss: https://leetcode.com/problems/number-of-zero-filled-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn zero_filled_subarray(nums: Vec<i32>) -> i64 {
47
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2348() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.