910. Smallest Range II Medium
1/**
2 * [910] Smallest Range II
3 *
4 * You are given an integer array nums and an integer k.
5 * For each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k.
6 * The score of nums is the difference between the maximum and minimum elements in nums.
7 * Return the minimum score of nums after changing the values at each index.
8 *
9 * Example 1:
10 *
11 * Input: nums = [1], k = 0
12 * Output: 0
13 * Explanation: The score is max(nums) - min(nums) = 1 - 1 = 0.
14 *
15 * Example 2:
16 *
17 * Input: nums = [0,10], k = 2
18 * Output: 6
19 * Explanation: Change nums to be [2, 8]. The score is max(nums) - min(nums) = 8 - 2 = 6.
20 *
21 * Example 3:
22 *
23 * Input: nums = [1,3,6], k = 3
24 * Output: 3
25 * Explanation: Change nums to be [4, 6, 3]. The score is max(nums) - min(nums) = 6 - 3 = 3.
26 *
27 *
28 * Constraints:
29 *
30 * 1 <= nums.length <= 10^4
31 * 0 <= nums[i] <= 10^4
32 * 0 <= k <= 10^4
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/smallest-range-ii/
38// discuss: https://leetcode.com/problems/smallest-range-ii/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn smallest_range_ii(nums: Vec<i32>, k: i32) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_910() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.