[알고리즘/프로그래머스] - 프린터(python)

유현민·2022년 6월 1일
0

알고리즘

목록 보기
198/253

문제

가장 높으면 출력하면서 answer += 1

없으면 맨 뒤로 보낸다.

deque를 이용하여 popleft사용해서 빼고 append로 넣기

from collections import deque


def solution(priorities, location):
    answer = 1
    p = deque(priorities)
    while p:
        m = max(p)
        if location == 0:
            if p[0] >= m:
                return answer
            else:
                p.append(p.popleft())

        elif p[0] >= m:
            p.popleft()
            answer += 1
        else:
            p.append(p.popleft())
        if location - 1 < 0:
            location = len(p) - 1
        else:
            location -= 1

    return answer
profile
smilegate megaport infra

0개의 댓글