Target Sum
Given an integer array nums and an integer target, return the number of ways to assign + or - to each element such that the sum equals target. All values in nums are non-negative integers; the + or - is the sign you assign to each element, not the element's original sign.
Two assignments are different if any single element receives a different sign, even when the two assignments pick equal values sitting at different positions.
nums = [1, 1, 1, 1, 1] target = 3
5
Exactly one element must be negative: -1+1+1+1+1, +1-1+1+1+1, +1+1-1+1+1, +1+1+1-1+1, +1+1+1+1-1. The five ones are equal in value but sit at different positions, so the five assignments count separately.
nums = [1, 2, 3] target = 6
1
The total of all elements is 6, so every element has to take a + sign. Flipping any one of them drops the sum by twice that element and overshoots downward, so +1+2+3 is the only assignment that works.
1 <= nums.length <= 200 <= nums[i] <= 10000 <= sum(nums) <= 1000-1000 <= target <= 1000