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 35a87bd

Browse files
Update 0416.分割等和子集.md
1 parent 072eb2a commit 35a87bd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎problems/0416.分割等和子集.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ class Solution:
324324
return True
325325
return False
326326

327+
```
328+
329+
卡哥版(简化版)
330+
```python
331+
class Solution:
332+
def canPartition(self, nums: List[int]) -> bool:
333+
if sum(nums) % 2 != 0:
334+
return False
335+
target = sum(nums) // 2
336+
dp = [0] * (target + 1)
337+
for num in nums:
338+
for j in range(target, num-1, -1):
339+
dp[j] = max(dp[j], dp[j-num] + num)
340+
return dp[-1] == target
341+
327342
```
328343
二维DP版
329344
```python

0 commit comments

Comments
(0)

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