You get an array nums of positive integers. Decide whether you can split it into two groups with equal sums. Every element goes into exactly one of the two groups, and a group may hold any of the elements, not just a run of neighbours.
Return true if such a split exists, otherwise false.
3 + 2 and 1 + 4 both make 5.
The total, 12, is even, so each group would need 6. But no choice of elements adds up to 6: the 7 is already too big, and 2 + 3 is only 5.
The total, 7, is odd, so it can never split into two equal whole halves.
Constraints
1 <= nums.length <= 2001 <= nums[i] <= 100If the total is odd, the answer is false. Otherwise the question becomes: can some of the numbers add up to exactly half the total?
true