cheetcode

115. Target SumMedium

Count ways to assign plus and minus signs to reach a target sum.

You are given an integer array nums and an integer target.

Return the number of different expressions you can build by adding either a plus or minus sign before each number so the total equals target.

Examples

Input: nums = [1,1,1,1,1], target = 3
Output: 5
Input: nums = [1], target = 1
Output: 1

Constraints

  • 1 <= nums.length <= 20
  • 0 <= nums[i] <= 1000
  • -1000 <= target <= 1000