You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers. For example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate them to build the expression "+2-1". Return the number of different expressions that you can build, which evaluates to target.
Example 1
Input: nums = [1,1,1,1,1], target = 3
Output: 5
Explanation: The five 1s add up to 5, so to reach 3 exactly one of them must get a '-' sign (4 - 1 = 3). There are 5 choices for which 1 gets the minus.
Example 2
Input: nums = [1], target = 1
Output: 1
Explanation: "+1" is the only expression that equals 1.
Example 3
Input: nums = [1], target = 2
Output: 0
Explanation: The only expressions are +1 and -1, and neither equals 2.
Split nums into a positive group P and a negative group N. Since P - N = target and P + N = total, P = (total + target) / 2. So the answer is the number of subsets summing to that fixed value.
Run checks all cases above. Submit evaluates all test cases.