Fundamentals/Equal Subsets
← PrevNext →
Given an array of positive integers nums, determine whether the array can be partitioned into two subsets whose sums are equal. Return true if such a partition exists, false otherwise.
Input
nums: an array of positive integers
Output
A boolean indicating whether a balanced partition exists.
Examples
Example 1
Inputnums = [1, 2, 3, 4, 5]
Outputfalse
Explanation: The total sum is 15, which is odd, so no equal split is possible.
Example 2
Inputnums = [10, 20]
Outputfalse
Constraints
1 <= nums.length <= 1000
The total sum of nums does not exceed 5000.