Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 00e96c4

Browse filesBrowse files
committed
Time: 41 ms (63.12%), Space: 13.9 MB (17.07%) - LeetHub
1 parent 7b25a96 commit 00e96c4
Copy full SHA for 00e96c4

File tree

1 file changed

+13
-0
lines changed
Filter options

1 file changed

+13
-0
lines changed
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def lastStoneWeight(self, stones: List[int]) -> int:
3+
for i, s in enumerate(stones):
4+
stones[i] = -s
5+
heapify(stones)
6+
while stones:
7+
s1 = -heappop(stones)
8+
if not stones:
9+
return s1
10+
s2 = -heappop(stones)
11+
if s1 > s2:
12+
heappush(stones, s2-s1)
13+
return 0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.