Skip to content

Commit 85a06b4

Browse files
committed
Do daily
1 parent a9f9b11 commit 85a06b4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

my-submissions/m416 v1.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def canPartition(self, nums: List[int]) -> bool:
3+
tot = sum(nums)
4+
if tot % 2 :
5+
return False
6+
dp = [True] + [False] * (tot // 2)
7+
8+
for num in nums :
9+
for i in range(len(dp) - 1, num - 1, -1) :
10+
dp[i] = dp[i] or dp[i - num]
11+
12+
return dp[-1]

0 commit comments

Comments
 (0)