1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-26 02:00:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/和相同的二元子数组 [binary-subarrays-with-sum].html

32 lines
892 B
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<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>