1509. Minimum Difference Between Largest and Smallest Value in Three Moves Medium
1/**
2 * [1509] Minimum Difference Between Largest and Smallest Value in Three Moves
3 *
4 * You are given an integer array nums. In one move, you can choose one element of nums and change it by any value.
5 * Return the minimum difference between the largest and smallest value of nums after performing at most three moves.
6 *
7 * Example 1:
8 *
9 * Input: nums = [5,3,2,4]
10 * Output: 0
11 * Explanation: Change the array [5,3,2,4] to [2,2,2,2].
12 * The difference between the maximum and minimum is 2-2 = 0.
13 *
14 * Example 2:
15 *
16 * Input: nums = [1,5,0,10,14]
17 * Output: 1
18 * Explanation: Change the array [1,5,0,10,14] to [1,1,0,1,1].
19 * The difference between the maximum and minimum is 1-0 = 1.
20 *
21 *
22 * Constraints:
23 *
24 * 1 <= nums.length <= 10^5
25 * -10^9 <= nums[i] <= 10^9
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/
31// discuss: https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn min_difference(nums: Vec<i32>) -> i32 {
37 0
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_1509() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.