Skip to content

Commit f306eec

Browse files
authored
Create destroying-asteroids.py
1 parent c6eb8a9 commit f306eec

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Python/destroying-asteroids.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(nlogn)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def asteroidsDestroyed(self, mass, asteroids):
6+
"""
7+
:type mass: int
8+
:type asteroids: List[int]
9+
:rtype: bool
10+
"""
11+
asteroids.sort()
12+
for x in asteroids:
13+
if x > mass:
14+
return False
15+
mass += min(x, asteroids[-1]-mass)
16+
return True

0 commit comments

Comments
 (0)