All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : April 07, 2025
Last updated : April 07, 2025
Related Topics : Array, Dynamic Programming
Acceptance Rate : 48.21 %
class Solution:
def canPartition(self, nums: List[int]) -> bool:
tot = sum(nums)
if tot % 2 :
return False
dp = [True] + [False] * (tot // 2)
for num in nums :
for i in range(len(dp) - 1, num - 1, -1) :
dp[i] = dp[i] or dp[i - num]
return dp[-1]