Partition equal subset sum
Standard · Write code · about 15 min
Return true if nums can be split into two groups with equal sums, and false otherwise. Every number goes into exactly one group.
Example 1
Input:
[[1,5,11,5]]
Output:
true
1 + 5 + 5 = 11.
Example 2
Input:
[[1,2,3,5]]
Output:
false
The total is 11, which is odd.
Constraints
- 1 ≤ nums.length ≤ 200
- 1 ≤ nums[i] ≤ 100
Learn the idea first: 0/1 and unbounded knapsack, a visual lesson.
More 0/1 and unbounded knapsack problems
- Fill the knapsack table Warm-up
- Take or skip? Warm-up
- 0/1 knapsack Standard
- Unbounded knapsack Standard
- Spot the bug: one-row 0/1 knapsack Standard
- Target sum Challenge