Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 937 Bytes

_416. Partition Equal Subset Sum.md

File metadata and controls

41 lines (28 loc) · 937 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : April 07, 2025

Last updated : April 07, 2025


Related Topics : Array, Dynamic Programming

Acceptance Rate : 48.21 %


Solutions

Python

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]