Skip to content

Instantly share code, notes, and snippets.

@milkyway103
Created September 21, 2019 12:47
Show Gist options
  • Save milkyway103/58b2b2bb9144b23a4c0f0a176f0355d0 to your computer and use it in GitHub Desktop.
Save milkyway103/58b2b2bb9144b23a4c0f0a176f0355d0 to your computer and use it in GitHub Desktop.
cnt = 0
def solution(numbers, target):
answer = 0
global cnt
dfs(0, numbers, 0, target)
return cnt
def dfs(index, numbers, temp, target):
global cnt
if index == len(numbers):
if temp == target:
cnt += 1
return
dfs(index+1, numbers, temp+numbers[index], target)
dfs(index+1, numbers, temp-numbers[index], target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment