Skip to content

Commit 21b6ce8

Browse files
authored
feat: add ts solution to lc problem: No.2126 (doocs#3188)
1 parent db83d05 commit 21b6ce8

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

solution/2100-2199/2126.Destroying Asteroids/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ func asteroidsDestroyed(mass int, asteroids []int) bool {
134134
}
135135
```
136136

137+
#### TypeScript
138+
139+
```ts
140+
function asteroidsDestroyed(mass: number, asteroids: number[]): boolean {
141+
asteroids.sort((a, b) => a - b);
142+
143+
for (const x of asteroids) {
144+
if (mass < x) return false;
145+
mass += x;
146+
}
147+
148+
return true;
149+
}
150+
```
151+
137152
<!-- tabs:end -->
138153

139154
<!-- solution:end -->

solution/2100-2199/2126.Destroying Asteroids/README_EN.md

+15
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ func asteroidsDestroyed(mass int, asteroids []int) bool {
134134
}
135135
```
136136

137+
#### TypeScript
138+
139+
```ts
140+
function asteroidsDestroyed(mass: number, asteroids: number[]): boolean {
141+
asteroids.sort((a, b) => a - b);
142+
143+
for (const x of asteroids) {
144+
if (mass < x) return false;
145+
mass += x;
146+
}
147+
148+
return true;
149+
}
150+
```
151+
137152
<!-- tabs:end -->
138153

139154
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function asteroidsDestroyed(mass: number, asteroids: number[]): boolean {
2+
asteroids.sort((a, b) => a - b);
3+
4+
for (const x of asteroids) {
5+
if (mass < x) return false;
6+
mass += x;
7+
}
8+
9+
return true;
10+
}

0 commit comments

Comments
 (0)