Merge pull request #299 from LiangDazhu/patch-25

添加 1049.最后一块石头的重量II.md python版本
This commit is contained in:
Carl Sun
2021-06-01 10:41:50 +08:00
committed by GitHub

View File

@ -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