Skip to content

Commit 4ebee48

Browse files
committed
Time: 6 ms (66.16%), Space: 19.1 MB (20.59%) - LeetHub
1 parent 5eeb1b5 commit 4ebee48

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def asteroidCollision(self, asteroids: List[int]) -> List[int]:
3+
stack = []
4+
5+
for a in asteroids:
6+
while stack and stack[-1] > 0 and a < 0:
7+
if stack[-1] < -a:
8+
stack.pop()
9+
continue
10+
elif stack[-1] == -a:
11+
stack.pop()
12+
break
13+
else:
14+
stack.append(a)
15+
16+
return stack

0 commit comments

Comments
 (0)