1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| class Solution:
def asteroidsDestroyed(self, mass: int, asteroids: List[int]) -> bool:
# Sort the asteroids in descending order
asteroids = sorted(asteroids)
# Iterate through the asteroids
for asteroid in asteroids:
# If the planet's mass is less than the mass of the asteroid, return False
if mass < asteroid:
return False
# Increase the planet's mass by the mass of the asteroid
mass += asteroid
# If all asteroids were destroyed, return True
return True
|