1 import heapq 2 class Solution: 3 def lastStoneWeight(self, stones: 'List[int]') -> int: 4 heapq._heapify_max(stones) 5 #r = [heapq._heappop_max(stones) for _ in range(len(stones))] 6 7 while len(stones) >= 2: 8 top = heapq._heappop_max(stones) 9 top2 = heapq._heappop_max(stones) 10 left = abs(top-top2) 11 if left != 0: 12 heapq.heappush(stones, left) 13 heapq._heapify_max(stones) 14 if len(stones) == 1: 15 last = heapq._heappop_max(stones) 16 return last 17 else: 18 return 0