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