algorithm/python
프로그래머스/DFS,BFS/타겟 넘버
아르르르를를르
2020. 3. 18. 22:11
https://programmers.co.kr/learn/courses/30/lessons/43165
level1
def solution(numbers, target):
answer = 0
def dfs(idx=0):
if idx < len(numbers):
numbers[idx] *= 1
dfs(idx+1)
numbers[idx] *= -1
dfs(idx+1)
elif sum(numbers) == target:
nonlocal answer
answer += 1
dfs()
return answer