Advertisement
smj007

Untitled

Feb 18th, 2024 (edited)
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. class Solution:
  2.     def lastStoneWeight(self, stones: List[int]) -> int:
  3.        
  4.         stones = [-s for s in stones]
  5.         heapq.heapify(stones)
  6.  
  7.         while (len(stones) > 1):
  8.             x = heapq.heappop(stones)
  9.             y = heapq.heappop(stones)
  10.             if x!=y :
  11.                 heapq.heappush(stones, x - y)
  12.  
  13.         return -stones[0] if len(stones) > 0 else 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement