We’re preparing your current view and syncing the latest data.
Given an integer array nums and a target integer S, you are tasked with assigning '+' and '-' signs to each element in nums such that the sum of all the signed elements equals S. Return the number of different ways you can achieve this target sum.
Example: Input: nums = [1,1,1,1,1], S = 3 Output: 5 Explanation: There are 5 ways to assign symbols to make sum 3:
An array of integers nums and an integer target S.
An integer representing the number of ways to assign '+' and '-' to elements in nums to achieve target sum S.
1 <= nums.length <= 20 0 <= nums[i] <= 1000 0 <= sum(nums[i]) <= 1000 -1000 <= S <= 1000
Example 1
Input
nums = [1,1,1,1,1], S = 3
Output
5
Explanation
There are 5 ways to assign symbols to achieve the sum 3 as described in the full description.