Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save automactic/78d09c214a0b952262c80b03b7492251 to your computer and use it in GitHub Desktop.
Save automactic/78d09c214a0b952262c80b03b7492251 to your computer and use it in GitHub Desktop.
class Solution:
def asteroidCollision(self, asteroids):
stack = []
for asteroid in asteroids:
stack.append(asteroid)
while(len(stack) >= 2):
if stack[-2] > 0 and stack[-1] < 0:
if abs(stack[-2]) > abs(stack[-1]):
stack.pop()
elif abs(stack[-2]) < abs(stack[-1]):
stack.pop(-2)
else:
stack.pop()
stack.pop()
else:
break
return stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment