Target Sum
Assign + or - to each array entry and sum the signed entries. Return the number of index-wise sign assignments producing target; zero entries still have two sign choices.
Example 1
nums = [1,1,1]
target = 13Explanation
Exactly one of three 1 entries must be negative, giving three assignments.
Example 2
nums = [0,0,1]
target = 14Explanation
Each zero independently takes either sign, giving four assignments while 1 is positive.
Example 3
nums = [2]
target = 10Explanation
The only sums are 2 and -2, neither matching 1.
Constraints
- 1 <= len(nums) <= 20
- Values are nonnegative
- Sum of values <= 1000
- abs(target) <= 1000
Function contract
findTargetSumWaysArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[1,1,1]1