Skip to content

Commit

Permalink
Update 1049.最后一块石头的重量II.md
Browse files Browse the repository at this point in the history
Added python version code
  • Loading branch information
LiangDazhu authored May 31, 2021
1 parent 5043002 commit 276a7b1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion problems/1049.最后一块石头的重量II.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,17 @@ class Solution {
```

Python:

```python
class Solution:
def lastStoneWeightII(self, stones: List[int]) -> int:
sumweight = sum(stones)
target = sumweight // 2
dp = [0] * 15001
for i in range(len(stones)):
for j in range(target, stones[i] - 1, -1):
dp[j] = max(dp[j], dp[j - stones[i]] + stones[i])
return sumweight - 2 * dp[target]
```

Go:

Expand Down

0 comments on commit 276a7b1

Please sign in to comment.