DevYoon
[ํ๋ก๊ทธ๋๋จธ์ค] ํ๊ฒ ๋๋ฒ (Python) ๋ณธ๋ฌธ
link ๐ https://programmers.co.kr/learn/courses/30/lessons/43165
1๏ธโฃ ๋ํ ๊ฒฝ์ฐ์ ๋บ ๊ฒฝ์ฐ๋ฅผ ๋๋ ์ DFS ๋๋ฆผ
def solution(numbers, target):
answer = 0
def dfs(level, sums):
global answer
if level == len(numbers):
if sums == target:
answer += 1
return
dfs(level+1, sums+numbers[level])
dfs(level+1, sums-numbers[level])
dfs(0, 0)
return answer