Leetcode 1127 Solution
This article provides solution to leetcode question 1127 (last-stone-weight)
Access this page by simply typing in "lcs 1127" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/last-stone-weight
Solution
class Solution:
def lastStoneWeight(self, stones: List[int]) -> int:
heap = []
for stone in stones:
heapq.heappush(heap, -stone)
while len(heap) > 1:
stone1 = -heapq.heappop(heap)
stone2 = -heapq.heappop(heap)
heapq.heappush(heap, stone2 - stone1)
return -heapq.heappop(heap)