mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个下标从 <strong>0</strong> 开始且长度为 <code>n</code> 的整数数组 <code>nums</code> 。<strong>分割</strong> 数组 <code>nums</code> 的方案数定义为符合以下两个条件的 <code>pivot</code> 数目:</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= pivot < n</code></li>
 | 
						||
	<li><code>nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1] + ... + nums[n - 1]</code></li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p>同时给你一个整数 <code>k</code> 。你可以将 <code>nums</code> 中 <strong>一个</strong> 元素变为 <code>k</code> 或 <strong>不改变</strong> 数组。</p>
 | 
						||
 | 
						||
<p>请你返回在 <strong>至多</strong> 改变一个元素的前提下,<strong>最多</strong> 有多少种方法 <strong>分割</strong> <code>nums</code> 使得上述两个条件都满足。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>nums = [2,-1,2], k = 3
 | 
						||
<b>输出:</b>1
 | 
						||
<b>解释:</b>一个最优的方案是将 nums[0] 改为 k 。数组变为 [<em><strong>3</strong></em>,-1,2] 。
 | 
						||
有一种方法分割数组:
 | 
						||
- pivot = 2 ,我们有分割 [3,-1 | 2]:3 + -1 == 2 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>nums = [0,0,0], k = 1
 | 
						||
<b>输出:</b>2
 | 
						||
<b>解释:</b>一个最优的方案是不改动数组。
 | 
						||
有两种方法分割数组:
 | 
						||
- pivot = 1 ,我们有分割 [0 | 0,0]:0 == 0 + 0 。
 | 
						||
- pivot = 2 ,我们有分割 [0,0 | 0]: 0 + 0 == 0 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33
 | 
						||
<b>输出:</b>4
 | 
						||
<b>解释:</b>一个最优的方案是将 nums[2] 改为 k 。数组变为 [22,4,<em><strong>-33</strong></em>,-20,-15,15,-16,7,19,-10,0,-13,-14] 。
 | 
						||
有四种方法分割数组。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>n == nums.length</code></li>
 | 
						||
	<li><code>2 <= n <= 10<sup>5</sup></code></li>
 | 
						||
	<li><code>-10<sup>5</sup> <= k, nums[i] <= 10<sup>5</sup></code></li>
 | 
						||
</ul>
 |