Target Sum

Given an integer array nums and an integer target, construct an expression by adding '+' or '-' before each integer in nums to match the target. Return the number of different expressions that evaluate to the target.

Constraints

  • 1 <= nums.length <= 20
  • 0 <= nums[i] <= 1000
  • 0 <= sum(nums[i]) <= 1000
  • -1000 <= target <= 1000
Saving… · 2 lines
class Solution:
def findTargetSumWays(self, nums: List[int], target: int) -> int:
Console

Click Run to execute sample tests.