-
-
Save milkyway103/58b2b2bb9144b23a4c0f0a176f0355d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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