mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given an integer array <code>nums</code>.</p>
 | 
						|
 | 
						|
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
 | 
						|
 | 
						|
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</strong></em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [5,3,2,4]
 | 
						|
<strong>Output:</strong> 0
 | 
						|
<strong>Explanation:</strong> We can make at most 3 moves.
 | 
						|
In the first move, change 2 to 3. nums becomes [5,3,3,4].
 | 
						|
In the second move, change 4 to 3. nums becomes [5,3,3,3].
 | 
						|
In the third move, change 5 to 3. nums becomes [3,3,3,3].
 | 
						|
After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [1,5,0,10,14]
 | 
						|
<strong>Output:</strong> 1
 | 
						|
<strong>Explanation:</strong> We can make at most 3 moves.
 | 
						|
In the first move, change 5 to 0. nums becomes [1,0,0,10,14].
 | 
						|
In the second move, change 10 to 0. nums becomes [1,0,0,0,14].
 | 
						|
In the third move, change 14 to 1. nums becomes [1,0,0,0,1].
 | 
						|
After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 1.
 | 
						|
It can be shown that there is no way to make the difference 0 in 3 moves.</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [3,100,20]
 | 
						|
<strong>Output:</strong> 0
 | 
						|
<strong>Explanation:</strong> We can make at most 3 moves.
 | 
						|
In the first move, change 100 to 7. nums becomes [3,7,20].
 | 
						|
In the second move, change 20 to 7. nums becomes [3,7,7].
 | 
						|
In the third move, change 3 to 7. nums becomes [7,7,7].
 | 
						|
After performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
 | 
						|
	<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
 | 
						|
</ul>
 |