|
4 | 4 |
|
5 | 5 | ## Description
|
6 | 6 |
|
7 |
| -<p>You are given an integer array <code>nums</code>. In one move, you can choose one element of <code>nums</code> and change it by <strong>any value</strong>.</p> |
| 7 | +<p>You are given an integer array <code>nums</code>.</p> |
8 | 8 |
|
9 |
| -<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> after performing <strong>at most three moves</strong></em>.</p> |
| 9 | +<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p> |
| 10 | + |
| 11 | +<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> |
10 | 12 |
|
11 | 13 | <p> </p>
|
12 | 14 | <p><strong class="example">Example 1:</strong></p>
|
13 | 15 |
|
14 | 16 | <pre>
|
15 | 17 | <strong>Input:</strong> nums = [5,3,2,4]
|
16 | 18 | <strong>Output:</strong> 0
|
17 |
| -<strong>Explanation:</strong> Change the array [5,3,2,4] to [<strong>2</strong>,<strong>2</strong>,2,<strong>2</strong>]. |
18 |
| -The difference between the maximum and minimum is 2-2 = 0. |
| 19 | +<strong>Explanation:</strong> We can make at most 3 moves. |
| 20 | +In the first move, change 2 to 3. nums becomes [5,3,3,4]. |
| 21 | +In the second move, change 4 to 3. nums becomes [5,3,3,3]. |
| 22 | +In the third move, change 5 to 3. nums becomes [3,3,3,3]. |
| 23 | +After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0. |
19 | 24 | </pre>
|
20 | 25 |
|
21 | 26 | <p><strong class="example">Example 2:</strong></p>
|
22 | 27 |
|
23 | 28 | <pre>
|
24 | 29 | <strong>Input:</strong> nums = [1,5,0,10,14]
|
25 | 30 | <strong>Output:</strong> 1
|
26 |
| -<strong>Explanation:</strong> Change the array [1,5,0,10,14] to [1,<strong>1</strong>,0,<strong>1</strong>,<strong>1</strong>]. |
27 |
| -The difference between the maximum and minimum is 1-0 = 1. |
| 31 | +<strong>Explanation:</strong> We can make at most 3 moves. |
| 32 | +In the first move, change 5 to 0. nums becomes [1,0,0,10,14]. |
| 33 | +In the second move, change 10 to 0. nums becomes [1,0,0,0,14]. |
| 34 | +In the third move, change 14 to 1. nums becomes [1,0,0,0,1]. |
| 35 | +After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 0. |
| 36 | +It can be shown that there is no way to make the difference 0 in 3 moves.</pre> |
| 37 | + |
| 38 | +<p><strong class="example">Example 3:</strong></p> |
| 39 | + |
| 40 | +<pre> |
| 41 | +<strong>Input:</strong> nums = [3,100,20] |
| 42 | +<strong>Output:</strong> 0 |
| 43 | +<strong>Explanation:</strong> We can make at most 3 moves. |
| 44 | +In the first move, change 100 to 7. nums becomes [4,7,20]. |
| 45 | +In the second move, change 20 to 7. nums becomes [4,7,7]. |
| 46 | +In the third move, change 4 to 3. nums becomes [7,7,7]. |
| 47 | +After performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0. |
28 | 48 | </pre>
|
29 | 49 |
|
30 | 50 | <p> </p>
|
|
0 commit comments