Skip to content

Commit 26b82d9

Browse files
authored
Create 1046-Last-Stone-Weight.py
1 parent 99c7b55 commit 26b82d9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

1046-Last-Stone-Weight.py

+13
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)