728x90

deque 에 적응을 많이 했고, 무조건 주석을 다는 습관이 필요한 것 같다. 사소한 것 때문에 시간을 좀 소비했다.

from collections import deque
 
def solution(priorities, location):
    answer = 1
 
    # 중요도가 클 수록 먼저 인쇄됌
 
 
    # 내가 구해야 할 index 변수 설정 후 체크해주기
    index = location
    print(index)
    stack = deque(priorities)
 
    while True:
        # 처음 것이 max 와 같다면
        if stack[0] == max(stack):
            print(stack)
            # 처음 것이 내가 찾는 거라면 break
            if index == 0:
 
                return answer
 
            # 내가 찾는 것이 아니라면
            else:
                print(index)
                stack.popleft()
                index-=1
                answer+=1
 
 
 
        # 처음 게 max 가 아니라면
 
        else:
            print(stack)
            # 처음이 내가 찾는 거라면
            if index == 0:
                index = len(stack)-1
                stack.append(stack[0])
                stack.popleft()
                print(index)
 
            # 내가 찾는 게 아니면
            else:
                index -= 1
                stack.append(stack[0])
                stack.popleft()
                print(index)
 
 
 
 
 
 
728x90

+ Recent posts