mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
32 lines
892 B
HTML
32 lines
892 B
HTML
<p>给你一个二元数组 <code>nums</code> ,和一个整数 <code>goal</code> ,请你统计并返回有多少个和为 <code>goal</code> 的<strong> 非空</strong> 子数组。</p>
|
||
|
||
<p><strong>子数组</strong> 是数组的一段连续部分。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [1,0,1,0,1], goal = 2
|
||
<strong>输出:</strong>4
|
||
<strong>解释:</strong>
|
||
有 4 个满足题目要求的子数组:[1,0,1]、[1,0,1,0]、[0,1,0,1]、[1,0,1]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [0,0,0,0,0], goal = 0
|
||
<strong>输出:</strong>15
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>
|
||
<li><code>nums[i]</code> 不是 <code>0</code> 就是 <code>1</code></li>
|
||
<li><code>0 <= goal <= nums.length</code></li>
|
||
</ul>
|