Skip to content

Commit 95dd969

Browse files
committed
feat: add 2nd ts solution to lc problem: No.2294
1 parent 26880b8 commit 95dd969

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,30 @@ function partitionArray(nums: number[], k: number): number {
177177

178178
<!-- solution:end -->
179179

180+
<!-- solution:start -->
181+
182+
### Solution 2
183+
184+
<!-- tabs:start -->
185+
186+
#### TypeScript
187+
188+
```ts
189+
function partitionArray(nums: number[], k: number): number {
190+
let c = 0;
191+
192+
while (nums.length) {
193+
const max = Math.max(...nums) - k;
194+
nums = nums.filter(x => x < max);
195+
c++;
196+
}
197+
198+
return c;
199+
}
200+
```
201+
202+
<!-- tabs:end -->
203+
204+
<!-- solution:end -->
205+
180206
<!-- problem:end -->

solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,30 @@ function partitionArray(nums: number[], k: number): number {
171171

172172
<!-- solution:end -->
173173

174+
<!-- solution:start -->
175+
176+
### Solution 2
177+
178+
<!-- tabs:start -->
179+
180+
#### TypeScript
181+
182+
```ts
183+
function partitionArray(nums: number[], k: number): number {
184+
let c = 0;
185+
186+
while (nums.length) {
187+
const max = Math.max(...nums) - k;
188+
nums = nums.filter(x => x < max);
189+
c++;
190+
}
191+
192+
return c;
193+
}
194+
```
195+
196+
<!-- tabs:end -->
197+
198+
<!-- solution:end -->
199+
174200
<!-- problem:end -->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function partitionArray(nums: number[], k: number): number {
2+
let c = 0;
3+
4+
while (nums.length) {
5+
const max = Math.max(...nums) - k;
6+
nums = nums.filter(x => x < max);
7+
c++;
8+
}
9+
10+
return c;
11+
}

0 commit comments

Comments
 (0)