Skip to content

Commit 50991e6

Browse files
authored
Create 1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.js
1 parent daf8454 commit 50991e6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const minDifference = function(nums) {
6+
let res = Infinity
7+
const n = nums.length
8+
if(n < 5) return 0
9+
nums.sort((a, b) => a - b)
10+
for(let i = 0; i < 4; i++) {
11+
res = Math.min(res, nums[n - 4 + i] - nums[i])
12+
}
13+
14+
return res
15+
};

0 commit comments

Comments
 (0)