Skip to content

Commit

Permalink
Merge pull request youngyangyang04#299 from LiangDazhu/patch-25
Browse files Browse the repository at this point in the history
添加 1049.最后一块石头的重量II.md python版本
  • Loading branch information
youngyangyang04 authored Jun 1, 2021
2 parents 8ffae04 + 276a7b1 commit dc0359f
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 dc0359f

Please sign in to comment.