File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 718
718
905|[ Sort Array By Parity] ( ./solutions/0905-sort-array-by-parity.js ) |Easy|
719
719
906|[ Super Palindromes] ( ./solutions/0906-super-palindromes.js ) |Hard|
720
720
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|
721
722
909|[ Snakes and Ladders] ( ./solutions/0909-snakes-and-ladders.js ) |Medium|
722
723
912|[ Sort an Array] ( ./solutions/0912-sort-an-array.js ) |Medium|
723
724
914|[ X of a Kind in a Deck of Cards] ( ./solutions/0914-x-of-a-kind-in-a-deck-of-cards.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments