Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. class Solution(object):
  2.  
  3. def findTargetSumWays(self, nums, S):
  4.  
  5. col = collections.defaultdict(list)
  6. ans = 0
  7.  
  8. def helpf(nums, S, sum, index):
  9. nonlocal col
  10. nonlocal ans
  11.  
  12. if index == len(nums):
  13. if sum == S:
  14. ans += 1
  15. else:
  16. col[(sum, index)] = 0
  17. helpf(nums, S, sum + nums[index], index+1)
  18. helpf(nums, S, sum - nums[index], index+1)
  19.  
  20. helpf(nums, S, 0, 0)
  21. return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement