Coding - Algo/python
[프로그래머스] 타겟 넘버 (python 파이썬)
jainn
2021. 7. 6. 23:11
728x90
문제
https://programmers.co.kr/learn/courses/30/lessons/43165
풀이 및 소스코드
bfs로 풀었다 !
from collections import deque
def solution(numbers, target):
answer = 0
s = deque()
s.append(0)
for number in numbers:
for _ in range(len(s)):
n = s.popleft()
s.append((n+number))
s.append((n-number))
answer = s.count(target)
return answer
반응형