Skip to content

Commit

Permalink
Update 1049.最后一块石头的重量II.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghongcheng authored Jun 23, 2023
1 parent 35a87bd commit 7198030
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions problems/1049.最后一块石头的重量II.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ class Solution:

return total_sum - dp[target] - dp[target]

```

卡哥版(简化版)
```python
class Solution:
def lastStoneWeightII(self, stones):
total_sum = sum(stones)
target = total_sum // 2
dp = [0] * (target + 1)
for stone in stones:
for j in range(target, stone - 1, -1):
dp[j] = max(dp[j], dp[j - stone] + stone)
return total_sum - 2* dp[-1]


```
二维DP版
```python
Expand Down

0 comments on commit 7198030

Please sign in to comment.