Update 1049.最后一块石头的重量II.md

Added python version code
This commit is contained in:
LiangDazhu
2021-05-31 21:34:11 +08:00
committed by GitHub
parent 5043002ed6
commit 276a7b1e14

View File

@ -178,7 +178,17 @@ class Solution {
``` ```
Python 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 Go