본문 바로가기
알고리즘/소스코드

PROGRAMMERS 43165: 타겟 넘버

by cjw.git 2021. 1. 5.

Link : programmers.co.kr/learn/courses/30/lessons/43165


Python

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
counter = 0
 
 
def DFS(numbers, target, deapth, length):
    global counter
    if deapth == length:
        if sum(numbers) == target:
            counter += 1
    else:
        numbers[deapth] *= -1
        DFS(numbers, target, deapth + 1, length)
        numbers[deapth] *= -1
        DFS(numbers, target, deapth + 1, length)
 
 
def solution(numbers, target):
    DFS(numbers, target, 0len(numbers))
    return counter
cs

FeedBack

  1.  

 

 

 

cjw.git@gmail.com

댓글