Asteroid Collision

We are given an array of integers representing asteroids in a row. The absolute value of each asteroid represents its size, and the sign represents its direction (positive for right, negative for left). Asteroids move at the same speed. When asteroids collide, the smaller one will explode. If they are the same size, both will explode. Asteroids moving in the same direction will not collide.

Constraints

  • 2 <= asteroids.length <= 10000
  • -1000 <= asteroids[i] <= 1000
  • asteroids[i] != 0
Saving… · 2 lines
class Solution:
def asteroidCollision(self, asteroids: List[int]) -> List[int]:
Console

Click Run to execute sample tests.