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 4b74640

Browse files
Create 416.py
1 parent 66b2ec9 commit 4b74640

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎101-500/416.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution(object):
2+
def canPartition(self, nums):
3+
totalSum = sum(nums)
4+
if totalSum % 2 != 0:
5+
return False
6+
targetSum = totalSum // 2
7+
dp = [False] * (targetSum + 1)
8+
dp[0] = True
9+
for num in nums:
10+
for currSum in range(targetSum, num - 1, -1):
11+
dp[currSum] = dp[currSum] or dp[currSum - num]
12+
return dp[targetSum]

0 commit comments

Comments
(0)

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