mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个数组 <code>nums</code> 和一个整数 <code>target</code> 。</p>
 | 
						||
 | 
						||
<p>请你返回 <strong>非空不重叠</strong> 子数组的最大数目,且每个子数组中数字和都为 <code>target</code> 。</p>
 | 
						||
 | 
						||
<p> </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> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= nums.length <= 10^5</code></li>
 | 
						||
	<li><code>-10^4 <= nums[i] <= 10^4</code></li>
 | 
						||
	<li><code>0 <= target <= 10^6</code></li>
 | 
						||
</ul>
 |