Untitled
unknown
plain_text
2 months ago
951 B
9
Indexable
class Solution(object): def asteroidCollision(self, asteroids): """ :type asteroids: List[int] :rtype: List[int] """ total=[] for i in asteroids: if i<0: print(total) if len(total) == 0: total.append(i) continue for j in range(len(total)-1, -1, -1): if (total[j]<0): total.append(i) break elif total[j] < abs(i): total.pop(-1) if (len(total) == 0): total.append(i) elif total[j] == abs(i): total.pop(-1) break elif total[j] > abs(i): break else: total.append(i) return(total)
Editor is loading...
Leave a Comment