We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 99c7b55 commit 26b82d9Copy full SHA for 26b82d9
1046-Last-Stone-Weight.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ def lastStoneWeight(self, stones: List[int]) -> int:
3
+ stones = [-s for s in stones]
4
+ heapq.heapify(stones)
5
+
6
+ while len(stones) > 1:
7
+ first = heapq.heappop(stones)
8
+ second = heapq.heappop(stones)
9
+ if second > first:
10
+ heapq.heappush(stones, first - second)
11
12
+ stones.append(0)
13
+ return abs(stones[0])
0 commit comments