File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# [ level 2] 타겟 넘버 - 43165
22
3- [ 문제 링크] ( https://school.programmers.co.kr/learn/courses/30/lessons/43165?language=java )
3+ [ 문제 링크] ( https://school.programmers.co.kr/learn/courses/30/lessons/43165?language=python3 )
44
55### 성능 요약
66
7- 메모리: 73.9 MB, 시간: 2.79 ms
7+ 메모리: 11.6 MB, 시간: 101.45 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2026년 05월 09일 01:54:35
19+ 2026년 07월 01일 22:18:21
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 1- from collections import deque
2-
31def solution (numbers , target ):
2+ global cnt
3+ n = len (numbers )
44 cnt = 0
55
6- q = deque ([(0 , numbers [0 ]), (0 , - numbers [0 ])])
7- while q :
8- i , total = q .popleft ()
9-
10- if i == len (numbers )- 1 and total == target :
11- cnt += 1
12- if i + 1 < len (numbers ):
13- q .append ((i + 1 , total + numbers [i + 1 ]))
14- q .append ((i + 1 , total - numbers [i + 1 ]))
15-
16- return cnt
6+ def dfs (i , total ):
7+ global cnt
8+ if i == n :
9+ if total == target :
10+ cnt += 1
11+ return
12+ else :
13+ dfs (i + 1 , total - numbers [i ])
14+ dfs (i + 1 , total + numbers [i ])
15+
16+ dfs (0 , 0 )
17+ return cnt
18+
You can’t perform that action at this time.
0 commit comments