Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions solution/2100-2199/2126.Destroying Asteroids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ func asteroidsDestroyed(mass int, asteroids []int) bool {
}
```

#### TypeScript

```ts
function asteroidsDestroyed(mass: number, asteroids: number[]): boolean {
asteroids.sort((a, b) => a - b);

for (const x of asteroids) {
if (mass < x) return false;
mass += x;
}

return true;
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
15 changes: 15 additions & 0 deletions solution/2100-2199/2126.Destroying Asteroids/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ func asteroidsDestroyed(mass int, asteroids []int) bool {
}
```

#### TypeScript

```ts
function asteroidsDestroyed(mass: number, asteroids: number[]): boolean {
asteroids.sort((a, b) => a - b);

for (const x of asteroids) {
if (mass < x) return false;
mass += x;
}

return true;
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
10 changes: 10 additions & 0 deletions solution/2100-2199/2126.Destroying Asteroids/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function asteroidsDestroyed(mass: number, asteroids: number[]): boolean {
asteroids.sort((a, b) => a - b);

for (const x of asteroids) {
if (mass < x) return false;
mass += x;
}

return true;
}