File tree Expand file tree Collapse file tree 2 files changed +23
-15
lines changed
Expand file tree Collapse file tree 2 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 10.3 MB, 시간: 378.77 ms
7+ 메모리: 98.6 MB, 시간: 642.91 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 03월 07일 15:06:29
19+ 2025년 04월 26일 16:05:51
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 1+ from collections import deque
2+
13def solution (numbers , target ):
2- global ans
3- ans = 0
4- def dfs (i , total ):
5- global ans
6- if (i == len (numbers )):
7- if target == total :
8- ans += 1
9- return
10- dfs (i + 1 , total + numbers [i ])
11- dfs (i + 1 , total - numbers [i ])
12- return
13- dfs (0 , 0 )
14- return ans
4+ global cnt
5+ cnt = 0
6+
7+ def bfs (numbers , target ):
8+ global cnt
9+ q = deque ([(0 , numbers [0 ]), (0 , - numbers [0 ])])
10+
11+ while q :
12+ i , total = q .popleft ()
13+
14+ if total == target and i == len (numbers ) - 1 :
15+ cnt += 1
16+ if i + 1 < len (numbers ):
17+ q .append ((i + 1 , total + numbers [i + 1 ]))
18+ q .append ((i + 1 , total - numbers [i + 1 ]))
19+
20+ bfs (numbers , target )
21+ return cnt
22+
You can’t perform that action at this time.
0 commit comments