Created
June 11, 2018 19:46
-
-
Save automactic/78d09c214a0b952262c80b03b7492251 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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