Skip to content

Commit 14b73ce

Browse files
authored
Create last-stone-weight-ii.py
1 parent 9a8449f commit 14b73ce

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: Python/last-stone-weight-ii.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(2^n)
2+
# Space: O(2^n)
3+
4+
class Solution(object):
5+
def lastStoneWeightII(self, stones):
6+
"""
7+
:type stones: List[int]
8+
:rtype: int
9+
"""
10+
dp = {0}
11+
for stone in stones:
12+
dp |= {stone+i for i in dp}
13+
S = sum(stones)
14+
return min(abs(i-(S-i)) for i in dp)

0 commit comments

Comments
 (0)