494. Target Sum
Practice Target Sum for free on NudgeCode: Medium, Dynamic Programming pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Put a + or - sign in front of every number in nums and add them all up. Return how many different sign choices give a total equal to target.
Example
nums = [1,1,1,1,1], target = 3 -> 5
(-1+1+1+1+1, +1-1+1+1+1, ... one minus sign in each of 5 places)
nums = [1], target = 1 -> 1
Constraints
- 1 <= nums.length <= 20
- 0 <= nums[i] <= 1000
- sum(nums) <= 1000
- -1000 <= target <= 1000