๋ฌธ์ ๋งํฌ
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
๋ณต์ฌ