Description
Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence.
Examples
Input:
nums = [1,3,0,0,2,0,0,4]Output:
6Explanation:
3 from first 0,0, 3 from second 0,0.
Input:
nums = [0,0,0,0]Output:
10Explanation:
All elements are zeros, forming one continuous segment of length 4. The subarrays are: [0], [0], [0], [0] (4 single elements), [0,0], [0,0], [0,0] (3 pairs), [0,0,0], [0,0,0] (2 triplets), and [0,0,0,0] (1 full array). Total: 4 + 3 + 2 + 1 = 10.
Input:
nums = [1,2,3,0,5,0,6]Output:
2Explanation:
There are two separate single zeros at indices 3 and 5. Each single zero forms exactly 1 subarray containing only that zero. Total: 1 + 1 = 2.
Constraints
- •
1 ≤ nums.length ≤ 10⁵