타겟넘버 - python(programmers)

참치돌고래·2021년 5월 18일
0

알고리즘

목록 보기
2/36
post-custom-banner

타켓넘버

--> https://programmers.co.kr/learn/courses/30/lessons/43165

from collections import deque

def solution(numbers, target):
    answer = 0
    
    queue = deque()
    queue.append([numbers[0],0])
    queue.append([-numbers[0],0])
    while queue:
        prior, level = queue.popleft()
        level +=1 
        if level < len(numbers):
            queue.append([prior+numbers[level],level])
            queue.append([prior-numbers[level],level])
        elif level ==len(numbers):
            if prior == target:
                answer+=1
            
        
        
    return answer
profile
안녕하세요
post-custom-banner

0개의 댓글