[프로그래머스] Lv2. 프로세스

lemythe423·2023년 7월 18일
0
post-thumbnail

📝 문제

풀이

deque를 활용한 풀이

큐에서 프로세스를 꺼내고 큐를 돌면서 더 우선순위가 높은 프로세스가 있나 확인한다. 더 높은 우선순위를 가진 프로세스가 있다면 지금 꺼낸 프로세스는 다시 큐에 넣는다. 이 과정의 반복

def solution(priorities, location):
    answer = 0
    queue = deque([(idx, x) for idx, x in enumerate(priorities)])

    while queue:
        i, x = queue.popleft()

        for j, y in queue:
            if x < y:
                queue.append((i, x))
                break
        else:
            answer += 1
            if i == location:
                return answer

from collections import deque
profile
아무말이나하기

1개의 댓글

comment-user-thumbnail
2023년 7월 18일

글이 많은 도움이 되었습니다, 감사합니다.

답글 달기