LC 1046 [E] Last Stone Weight - ALawliet/algorithms GitHub Wiki

from queue import PriorityQueue

class Solution:
    def lastStoneWeight(self, stones: List[int]) -> int:
        max_heap = PriorityQueue()
        for stone in stones:
            max_heap.put(-stone)
        
        while max_heap.qsize() >= 2:
            first = -max_heap.get()
            second = -max_heap.get()
            if first > second:
                smashed = first - second
                max_heap.put(-smashed)
                
        return -max_heap.queue[0] if max_heap.qsize() else 0