https://school.programmers.co.kr/learn/courses/30/lessons/43165
from collections import deque
def solution(numbers, target):
answer = 0
q = deque([[numbers[0],0],[-1*numbers[0],0]])
while q:
num,idx = q.popleft()
idx+=1
if idx<len(numbers):
q.append([num+numbers[idx],idx])
q.append([num - numbers[idx], idx])
else:
if num == target:
answer+=1
return answer
스택에 모든 케이스를 저장해가면서 문제를 풀었다.