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 @@ -160,32 +160,36 @@ func minDifference(nums []int) int {
160
160
161
161
``` ts
162
162
function minDifference(nums : number []): number {
163
- if (nums .length < 5 ) return 0 ;
163
+ if (nums .length < 5 ) {
164
+ return 0 ;
165
+ }
164
166
nums .sort ((a , b ) => a - b );
165
- let res = Number .POSITIVE_INFINITY;
166
-
167
+ let ans = Number .POSITIVE_INFINITY;
167
168
for (let i = 0 ; i < 4 ; i ++ ) {
168
- res = Math .min (res , nums .at (i - 4 )! - nums [i ]);
169
+ ans = Math .min (ans , nums .at (i - 4 )! - nums [i ]);
169
170
}
170
-
171
- return res ;
171
+ return ans ;
172
172
}
173
173
```
174
174
175
175
#### JavaScript
176
176
177
177
``` js
178
- function minDifference (nums ) {
179
- if (nums .length < 5 ) return 0 ;
178
+ /**
179
+ * @param {number[]} nums
180
+ * @return {number}
181
+ */
182
+ var minDifference = function (nums ) {
183
+ if (nums .length < 5 ) {
184
+ return 0 ;
185
+ }
180
186
nums .sort ((a , b ) => a - b);
181
187
let ans = Number .POSITIVE_INFINITY ;
182
-
183
188
for (let i = 0 ; i < 4 ; i++ ) {
184
189
ans = Math .min (ans, nums .at (i - 4 ) - nums[i]);
185
190
}
186
-
187
191
return ans;
188
- }
192
+ };
189
193
```
190
194
191
195
<!-- tabs: end -->
You can’t perform that action at this time.
0 commit comments