1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/和相同的二元子数组 [binary-subarrays-with-sum].html
2022-03-29 12:43:11 +08:00

32 lines
892 B
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>