|
| 1 | +<p>Given a binary array <code>nums</code> and an integer <code>goal</code>, return <em>the number of non-empty <strong>subarrays</strong> with a sum</em> <code>goal</code>.</p> |
| 2 | + |
| 3 | +<p>A <strong>subarray</strong> is a contiguous part of the array.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2 |
| 10 | +<strong>Output:</strong> 4 |
| 11 | +<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below: |
| 12 | +[<u><strong>1,0,1</strong></u>,0,1] |
| 13 | +[<u><strong>1,0,1,0</strong></u>,1] |
| 14 | +[1,<u><strong>0,1,0,1</strong></u>] |
| 15 | +[1,0,<u><strong>1,0,1</strong></u>] |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> nums = [0,0,0,0,0], goal = 0 |
| 22 | +<strong>Output:</strong> 15 |
| 23 | +</pre> |
| 24 | + |
| 25 | +<p> </p> |
| 26 | +<p><strong>Constraints:</strong></p> |
| 27 | + |
| 28 | +<ul> |
| 29 | + <li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li> |
| 30 | + <li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li> |
| 31 | + <li><code>0 <= goal <= nums.length</code></li> |
| 32 | +</ul> |
0 commit comments