Search
Duplicate
๐Ÿ”ฅ

ํƒ€๊ฒŸ ๋„˜๋ฒ„

์ฃผ์ฐจ
๋ฌธ์ œ๋ฒˆํ˜ธ
์–ธ์–ด
Python
ํ‹ฐ์–ด
Level 2
์œ ํ˜•
DFS
BFS
nj_Blog
O
nj_์ƒํƒœ
์™„๋ฃŒ
์ดํ•ด๋„
ํ’€์ด
์‚ฌ๋žŒ
์ดํ•ด๋„ 2
13 more properties

๋ฌธ์ œ๋งํฌ

Code

from collections import deque def solution(numbers, target): answer = 0 queue = deque() n = len(numbers) queue.append([numbers[0],0]) queue.append([-1*numbers[0],0]) while queue: temp, idx = queue.popleft() idx += 1 if idx < n: queue.append([temp+numbers[idx], idx]) queue.append([temp-numbers[idx], idx]) else: if temp == target: answer += 1 return answer
Python
๋ณต์‚ฌ
from collections import deque def solution(numbers, target): cal = deque() cal.append(0) for num in numbers: cal_len = len(cal) for _ in range(cal_len): prev = cal.popleft() cal.append(prev + num) cal.append(prev - num) return cal.count(target)
Python
๋ณต์‚ฌ