@laigary.com~/interview/coding/1046-last-stone-weight.md$
$ cat ./coding/1046-last-stone-weight.md
[Coding]·2023-12-28·1 min read

1046. Last Stone Weight

1046. Last Stone Weight

class Solution:
    def lastStoneWeight(self, stones: List[int]) -> int:
        heap = []
        for stone in stones:
            heapq.heappush(heap, -1 * stone)
        
        while len(heap) > 1:
            first = heapq.heappop(heap)
            second = heapq.heappop(heap)
            if first != second:
                heapq.heappush(heap, first - second)
        
        if len(heap) == 0:
            return 0
        else:
            return -1 * heap[0]