File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed
solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -171,32 +171,36 @@ func minDifference(nums []int) int {
171
171
172
172
``` ts
173
173
function minDifference(nums : number []): number {
174
- if (nums .length < 5 ) return 0 ;
174
+ if (nums .length < 5 ) {
175
+ return 0 ;
176
+ }
175
177
nums .sort ((a , b ) => a - b );
176
- let res = Number .POSITIVE_INFINITY;
177
-
178
+ let ans = Number .POSITIVE_INFINITY;
178
179
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 ]);
180
181
}
181
-
182
- return res ;
182
+ return ans ;
183
183
}
184
184
```
185
185
186
186
#### JavaScript
187
187
188
188
``` 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
+ }
191
197
nums .sort ((a , b ) => a - b);
192
198
let ans = Number .POSITIVE_INFINITY ;
193
-
194
199
for (let i = 0 ; i < 4 ; i++ ) {
195
200
ans = Math .min (ans, nums .at (i - 4 ) - nums[i]);
196
201
}
197
-
198
202
return ans;
199
- }
203
+ };
200
204
```
201
205
202
206
<!-- tabs: end -->
You can’t perform that action at this time.
0 commit comments