1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/和为目标值且不重叠的非空子数组的最大数目 [maximum-number-of-non-overlapping-subarrays-with-sum-equals-target].html
2022-03-29 12:43:11 +08:00

42 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>给你一个数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>target</code>&nbsp;</p>
<p>请你返回&nbsp;<strong>非空不重叠</strong>&nbsp;子数组的最大数目,且每个子数组中数字和都为 <code>target</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>nums = [1,1,1,1,1], target = 2
<strong>输出:</strong>2
<strong>解释:</strong>总共有 2 个不重叠子数组(加粗数字表示) [<strong>1,1</strong>,1,<strong>1,1</strong>] ,它们的和为目标值 2 。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>nums = [-1,3,5,1,4,2,-9], target = 6
<strong>输出:</strong>2
<strong>解释:</strong>总共有 3 个子数组和为 6 。
([5,1], [4,2], [3,5,1,4,2,-9]) 但只有前 2 个是不重叠的。</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>nums = [-2,6,6,3,5,4,1,2,8], target = 10
<strong>输出:</strong>3
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>nums = [0,0,0], target = 0
<strong>输出:</strong>3
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;=&nbsp;10^5</code></li>
<li><code>-10^4 &lt;= nums[i] &lt;=&nbsp;10^4</code></li>
<li><code>0 &lt;= target &lt;= 10^6</code></li>
</ul>