mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Update 1049.最后一块石头的重量II.md
This commit is contained in:
@ -238,6 +238,21 @@ class Solution:
|
|||||||
|
|
||||||
return total_sum - dp[target] - dp[target]
|
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版
|
二维DP版
|
||||||
```python
|
```python
|
||||||
|
Reference in New Issue
Block a user