이모저모

타겟넘버 - 프로그래머스 (DFS로 풀기) 본문

coding/알고리즘,자료구조

타겟넘버 - 프로그래머스 (DFS로 풀기)

Jeo 2022. 1. 27. 11:32

먼저 손정리!

def solution(numbers, target):
    count = 0
    def DFS(L, S):
        nonlocal count
        if L == len(numbers):
            if S == target:
                count += 1
            return
        else:
            DFS(L+1, S + numbers[L])
            DFS(L + 1, S - numbers[L])
    DFS(0, 0)

    return count
Comments