This repository contains a Python solution to the classic "Partition Equal Subset Sum" problem from LeetCode, solved using an optimized Dynamic Programming approach.
Given a non-empty array nums
containing only positive integers, determine if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
- Calculate the total sum of all elements.
- If the sum is odd, return
False
(can't split into two equal subsets). - If even, check if there's a subset with sum = total // 2 using 1D Dynamic Programming.
- Time Complexity:
O(n * sum)
- Space Complexity:
O(sum)
Feel free to star ⭐ the repo and share with others if you find this helpful.