mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
43 lines
1.5 KiB
HTML
43 lines
1.5 KiB
HTML
<p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
|
|
|
|
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [1,3,0,0,2,0,0,4]
|
|
<strong>Output:</strong> 6
|
|
<strong>Explanation:</strong>
|
|
There are 4 occurrences of [0] as a subarray.
|
|
There are 2 occurrences of [0,0] as a subarray.
|
|
There is no occurrence of a subarray with a size more than 2 filled with 0. Therefore, we return 6.</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [0,0,0,2,0,0]
|
|
<strong>Output:</strong> 9
|
|
<strong>Explanation:
|
|
</strong>There are 5 occurrences of [0] as a subarray.
|
|
There are 3 occurrences of [0,0] as a subarray.
|
|
There is 1 occurrence of [0,0,0] as a subarray.
|
|
There is no occurrence of a subarray with a size more than 3 filled with 0. Therefore, we return 9.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [2,10,2019]
|
|
<strong>Output:</strong> 0
|
|
<strong>Explanation:</strong> There is no subarray filled with 0. Therefore, we return 0.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
|
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
|
</ul>
|