Skip to content

Commit dd9723a

Browse files
authored
Update README.md
1 parent 9ab93d4 commit dd9723a

File tree

1 file changed

+15
-11
lines changed
  • solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves

1 file changed

+15
-11
lines changed

solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,32 +171,36 @@ func minDifference(nums []int) int {
171171

172172
```ts
173173
function minDifference(nums: number[]): number {
174-
if (nums.length < 5) return 0;
174+
if (nums.length < 5) {
175+
return 0;
176+
}
175177
nums.sort((a, b) => a - b);
176-
let res = Number.POSITIVE_INFINITY;
177-
178+
let ans = Number.POSITIVE_INFINITY;
178179
for (let i = 0; i < 4; i++) {
179-
res = Math.min(res, nums.at(i - 4)! - nums[i]);
180+
ans = Math.min(ans, nums.at(i - 4)! - nums[i]);
180181
}
181-
182-
return res;
182+
return ans;
183183
}
184184
```
185185

186186
#### JavaScript
187187

188188
```js
189-
function minDifference(nums) {
190-
if (nums.length < 5) return 0;
189+
/**
190+
* @param {number[]} nums
191+
* @return {number}
192+
*/
193+
var minDifference = function (nums) {
194+
if (nums.length < 5) {
195+
return 0;
196+
}
191197
nums.sort((a, b) => a - b);
192198
let ans = Number.POSITIVE_INFINITY;
193-
194199
for (let i = 0; i < 4; i++) {
195200
ans = Math.min(ans, nums.at(i - 4) - nums[i]);
196201
}
197-
198202
return ans;
199-
}
203+
};
200204
```
201205

202206
<!-- tabs:end -->

0 commit comments

Comments
 (0)