mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 1049.最后一块石头的重量II.md
Added python version code
This commit is contained in:
@ -178,7 +178,17 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
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:
|
Go:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user