Skip to content

Commit 89a1805

Browse files
committed
[level 2] Title: 타겟 넘버, Time: 677.63 ms, Memory: 98.9 MB -BaekjoonHub
1 parent 458fcfc commit 89a1805

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

프로그래머스/2/43165. 타겟 넘버/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 98.6 MB, 시간: 642.91 ms
7+
메모리: 98.9 MB, 시간: 677.63 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 04월 26일 16:05:51
19+
2025년 04월 26일 16:15:56
2020

2121
### 문제 설명
2222

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
from 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

0 commit comments

Comments
 (0)