← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Practice/Meta/Leetcode 494. Target Sum
CodingMust
You are given an array of integers nums and an integer target. Your task is to build an expression by placing either a + (plus) or - (minus) operator before each number in the array. The expression should evaluate to the target value.
Return the number of different expressions you can build that evaluate to target.
+ or - before each element in numstarget sumnums must be used exactly onceExample 1:
` Input: nums = [1, 1, 1, 1, 1], target = 3 Output: 5 Explanation: There are 5 ways to assign symbols to reach target 3:
Example 2:
Input: nums = [1], target = 1 Output: 1 Explanation: Only one way: +1 = 1
Example 3:
` Input: nums = [1, 2, 3], target = 0 Output: 2 Explanation: Two ways: