T: O(nlogn)
S: O(1)
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; } }
Last updated 2 years ago