Last Stone Weight LeetCode solution in Python
1# Runtime: 59 ms (Top 27.86%) | Memory: 13.9 MB (Top 62.57%)2class Solution:3def lastStoneWeight(self, stones: List[int]) -> int:4stones = [-x for x in stones]5heapq.heapify(stones)67while len(stones) > 1:8mx1 = -heapq.heappop(stones)9mx2 = -heapq.heappop(stones)10if mx1 - mx2:11heapq.heappush(stones, -(mx1 - mx2))1213if len(stones):14return -heapq.heappop(stones)15return 0