Skip to content

Commit 65cb1b5

Browse files
committedMar 24, 2025
Add solution #908
1 parent c65e000 commit 65cb1b5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@
718718
905|[Sort Array By Parity](./solutions/0905-sort-array-by-parity.js)|Easy|
719719
906|[Super Palindromes](./solutions/0906-super-palindromes.js)|Hard|
720720
907|[Sum of Subarray Minimums](./solutions/0907-sum-of-subarray-minimums.js)|Medium|
721+
908|[Smallest Range I](./solutions/0908-smallest-range-i.js)|Easy|
721722
909|[Snakes and Ladders](./solutions/0909-snakes-and-ladders.js)|Medium|
722723
912|[Sort an Array](./solutions/0912-sort-an-array.js)|Medium|
723724
914|[X of a Kind in a Deck of Cards](./solutions/0914-x-of-a-kind-in-a-deck-of-cards.js)|Medium|

‎solutions/0908-smallest-range-i.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 908. Smallest Range I
3+
* https://leetcode.com/problems/smallest-range-i/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums and an integer k.
7+
*
8+
* In one operation, you can choose any index i where 0 <= i < nums.length and change nums[i] to
9+
* nums[i] + x where x is an integer from the range [-k, k]. You can apply this operation at most
10+
* once for each index i.
11+
*
12+
* The score of nums is the difference between the maximum and minimum elements in nums.
13+
*
14+
* Return the minimum score of nums after applying the mentioned operation at most once for each
15+
* index in it.
16+
*/
17+
18+
/**
19+
* @param {number[]} nums
20+
* @param {number} k
21+
* @return {number}
22+
*/
23+
var smallestRangeI = function(nums, k) {
24+
return Math.max(Math.max(...nums) - Math.min(...nums) - 2 * k, 0);
25+
};

0 commit comments

Comments
 (0)
Please sign in to comment.