[프로그래머스] 프린터 Python

김아현·2022년 5월 9일
0

문제 보기

🔒 문제

🔐 해결 과정

  1. 인쇄 대기목록에서 0번째 문서의 우선순위가 인쇄 대기목록의 최대값과 일치하는지 확인한다. (우선순위 비교)
    1-1. 일치하면 맨 앞의 문서를 꺼내고 인쇄 카운트를 1 증가시킨다. 여기서 location이 0이라면 내가 요청한 문서이기 때문에 카운트를 반환하면서 종료한다.
    1-2. 일치하지 않으면 맨 앞의 문서를 대기목록 뒤에 넣어주고 location을 그에 맞게 설정한다.

🔓 풀이 (30m)

2020.

def solution(priorities, location):
    cnt = 0
    while priorities:
        if priorities[0] == max(priorities):
            priorities.pop(0)
            cnt += 1
            if location == 0: return cnt
            else: location -= 1
        else:
            priorities.append(priorities.pop(0))
            if location == 0 : location = len(priorities)-1
            else: location -= 1
    return cnt

2022.5.9

def solution(priorities, location):
    cnt = 0
    while(len(priorities)) :
        if(priorities[0] >= max(priorities)):
            priorities.pop(0)
            cnt += 1
            if(location == 0): return cnt
        else:
            priorities.append(priorities.pop(0))
        location = location-1 if location != 0 else len(priorities)-1
profile
Want to be backend developer

0개의 댓글