Target sum with signs
Mediumdynamic programmingbacktrackingarray
Put a + or - in front of every number in nums. Return how many ways the result equals target.
Example 1
Input: nums = [1,1,1,1,1], target = 3 Output: 5
Example 2
Input: nums = [1], target = 1 Output: 1
Constraints
- 1 ≤ nums.length ≤ 20
- 0 ≤ nums[i] ≤ 1000
- sum(nums) ≤ 1000
- -1000 ≤ target ≤ 1000
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {int[]} nums
* @param {int} target
* @return {int}
*/
function findTargetSumWays(nums, target) {
}