Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7198030

Browse files
Update 1049.最后一块石头的重量II.md
1 parent 35a87bd commit 7198030

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎problems/1049.最后一块石头的重量II.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ class Solution:
238238

239239
return total_sum - dp[target] - dp[target]
240240

241+
```
242+
243+
卡哥版(简化版)
244+
```python
245+
class Solution:
246+
def lastStoneWeightII(self, stones):
247+
total_sum = sum(stones)
248+
target = total_sum // 2
249+
dp = [0] * (target + 1)
250+
for stone in stones:
251+
for j in range(target, stone - 1, -1):
252+
dp[j] = max(dp[j], dp[j - stone] + stone)
253+
return total_sum - 2* dp[-1]
254+
255+
241256
```
242257
二维DP版
243258
```python

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /