Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3dc80c3

Browse files
authored
feat: add solutions to lc problem: No.1509 (doocs#3198)
1 parent 01ffed2 commit 3dc80c3

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,42 @@ func minDifference(nums []int) int {
167167
}
168168
```
169169

170+
#### TypeScript
171+
172+
```ts
173+
function minDifference(nums: number[]): number {
174+
if (nums.length < 5) {
175+
return 0;
176+
}
177+
nums.sort((a, b) => a - b);
178+
let ans = Number.POSITIVE_INFINITY;
179+
for (let i = 0; i < 4; i++) {
180+
ans = Math.min(ans, nums.at(i - 4)! - nums[i]);
181+
}
182+
return ans;
183+
}
184+
```
185+
186+
#### JavaScript
187+
188+
```js
189+
/**
190+
* @param {number[]} nums
191+
* @return {number}
192+
*/
193+
var minDifference = function (nums) {
194+
if (nums.length < 5) {
195+
return 0;
196+
}
197+
nums.sort((a, b) => a - b);
198+
let ans = Number.POSITIVE_INFINITY;
199+
for (let i = 0; i < 4; i++) {
200+
ans = Math.min(ans, nums.at(i - 4) - nums[i]);
201+
}
202+
return ans;
203+
};
204+
```
205+
170206
<!-- tabs:end -->
171207

172208
<!-- solution:end -->

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,42 @@ func minDifference(nums []int) int {
156156
}
157157
```
158158

159+
#### TypeScript
160+
161+
```ts
162+
function minDifference(nums: number[]): number {
163+
if (nums.length < 5) {
164+
return 0;
165+
}
166+
nums.sort((a, b) => a - b);
167+
let ans = Number.POSITIVE_INFINITY;
168+
for (let i = 0; i < 4; i++) {
169+
ans = Math.min(ans, nums.at(i - 4)! - nums[i]);
170+
}
171+
return ans;
172+
}
173+
```
174+
175+
#### JavaScript
176+
177+
```js
178+
/**
179+
* @param {number[]} nums
180+
* @return {number}
181+
*/
182+
var minDifference = function (nums) {
183+
if (nums.length < 5) {
184+
return 0;
185+
}
186+
nums.sort((a, b) => a - b);
187+
let ans = Number.POSITIVE_INFINITY;
188+
for (let i = 0; i < 4; i++) {
189+
ans = Math.min(ans, nums.at(i - 4) - nums[i]);
190+
}
191+
return ans;
192+
};
193+
```
194+
159195
<!-- tabs:end -->
160196

161197
<!-- solution:end -->
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+
var minDifference = function (nums) {
6+
if (nums.length < 5) {
7+
return 0;
8+
}
9+
nums.sort((a, b) => a - b);
10+
let ans = Number.POSITIVE_INFINITY;
11+
for (let i = 0; i < 4; i++) {
12+
ans = Math.min(ans, nums.at(i - 4) - nums[i]);
13+
}
14+
return ans;
15+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function minDifference(nums: number[]): number {
2+
if (nums.length < 5) {
3+
return 0;
4+
}
5+
nums.sort((a, b) => a - b);
6+
let ans = Number.POSITIVE_INFINITY;
7+
for (let i = 0; i < 4; i++) {
8+
ans = Math.min(ans, nums.at(i - 4)! - nums[i]);
9+
}
10+
return ans;
11+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /