https://leetcode.com/problems/target-sum/description/

1) 코드
class Solution:
def findTargetSumWays(self, nums: List[int], target: int) -> int:
memo = {}
def bt(index, currentSum):
if index == len(nums):
return 1 if currentSum == target else 0
if (index, currentSum) in memo:
return memo[(index, currentSum)]
addition = bt(index+1, currentSum + nums[index])
subtraction = bt(index+1, currentSum - nums[index])
memo[(index, currentSum)] = addition+subtraction
return addition+subtraction
return bt(0, 0)
2) 해설