mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0416.分割等和子集.md
This commit is contained in:
@ -324,6 +324,21 @@ class Solution:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
卡哥版(简化版)
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def canPartition(self, nums: List[int]) -> bool:
|
||||||
|
if sum(nums) % 2 != 0:
|
||||||
|
return False
|
||||||
|
target = sum(nums) // 2
|
||||||
|
dp = [0] * (target + 1)
|
||||||
|
for num in nums:
|
||||||
|
for j in range(target, num-1, -1):
|
||||||
|
dp[j] = max(dp[j], dp[j-num] + num)
|
||||||
|
return dp[-1] == target
|
||||||
|
|
||||||
```
|
```
|
||||||
二维DP版
|
二维DP版
|
||||||
```python
|
```python
|
||||||
|
Reference in New Issue
Block a user