Skip to content

Commit 6f614aa

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Create 735. Asteroid Collision.py
Co-Authored-By: Antim-IWP <[email protected]> Co-Authored-By: Shiwangi Srivastava <[email protected]>
1 parent abb1f0f commit 6f614aa

File tree

1 file changed

+14
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)