mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个整数数组 <code>arr</code> 和一个目标值 <code>target</code> ,请你返回一个整数 <code>value</code> ,使得将数组中所有大于 <code>value</code> 的值变成 <code>value</code> 后,数组的和最接近  <code>target</code> (最接近表示两者之差的绝对值最小)。</p>
 | 
						||
 | 
						||
<p>如果有多种使得和最接近 <code>target</code> 的方案,请你返回这些整数中的最小值。</p>
 | 
						||
 | 
						||
<p>请注意,答案不一定是 <code>arr</code> 中的数字。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [4,9,3], target = 10
 | 
						||
<strong>输出:</strong>3
 | 
						||
<strong>解释:</strong>当选择 value 为 3 时,数组会变成 [3, 3, 3],和为 9 ,这是最接近 target 的方案。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [2,3,5], target = 10
 | 
						||
<strong>输出:</strong>5
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [60864,25176,27249,21296,20204], target = 56803
 | 
						||
<strong>输出:</strong>11361
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= arr.length <= 10^4</code></li>
 | 
						||
	<li><code>1 <= arr[i], target <= 10^5</code></li>
 | 
						||
</ul>
 |