유형 : 구현

풀이 시간: 15분

 

def solution(priorities, location):
    answer = []
    tf = [False for i in range(len(priorities))]
    tf[location] = True
    cnt = 0
    while priorities:
        curr = priorities.pop(0)
        tfcurr = tf.pop(0)
        if priorities and curr < max(priorities):
            priorities.append(curr)
            tf.append(tfcurr)
        else:
            cnt += 1
            if tfcurr == True:
                return cnt

 

간단한 queue 문제였다.

풀이 자체는 어렵지 않았지만, max(priorities) 에서 자꾸 오류가 나서 애먹었다.

빈 배열에 대해 max할 때 error가 난다는 것을 찾아 해결했다. 

복사했습니다!