mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Merge pull request #299 from LiangDazhu/patch-25
添加 1049.最后一块石头的重量II.md python版本
This commit is contained in:
@ -178,7 +178,17 @@ class Solution {
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
|
Reference in New Issue
Block a user