(nums, target, index, sum)
| 19 | }; |
| 20 | |
| 21 | var dfs = (nums, target, index, sum) => { |
| 22 | const left = findTargetSumWays( |
| 23 | nums, |
| 24 | target, |
| 25 | index + 1, |
| 26 | sum + nums[index], |
| 27 | ); /* Time O(2^N) | Space O(HEIGHT) */ |
| 28 | const right = findTargetSumWays( |
| 29 | nums, |
| 30 | target, |
| 31 | index + 1, |
| 32 | sum - nums[index], |
| 33 | ); /* Time O(2^N) | Space O(HEIGHT) */ |
| 34 | |
| 35 | return left + right; |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * DP - Top Down |
no test coverage detected