We are given an array asteroids
of integers representing asteroids in a row.
For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
Example 1:
Example 2:
Example 3:
Constraints:
asteroids.length
<= 104asteroids[i]
<= 1000asteroids[i]
!= 0Yen-Chi ChenThu, Jul 20, 2023
MarsgoatThu, Jul 20, 2023
稍微改了一下,把pop出來又push進去的愚蠢行為改掉了。
MarsgoatThu, Jul 20, 2023