diff --git a/problems/1049.最后一块石头的重量II.md b/problems/1049.最后一块石头的重量II.md index a978b802..932029ab 100644 --- a/problems/1049.最后一块石头的重量II.md +++ b/problems/1049.最后一块石头的重量II.md @@ -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