> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/weekly-contest/weekly-contest-274/2126.-destroying-asteroids.md).

# 2126. Destroying Asteroids

T: O(nlogn)

S: O(1)

```java
class Solution {
    public boolean asteroidsDestroyed(int mass, int[] asteroids) {
        Arrays.sort(asteroids);
        long acc = (long)mass;
        for (int asteroid : asteroids) {
            if (acc >= asteroid) {
                acc += asteroid;
            } else {
                return false;
            }
        }
        return true;
    }
}
```
