문제
코드
from collections import deque
def solution(priorities: list, location: int) -> int:
priorities = [[index, data] for index, data in enumerate(priorities)]
queue, relocation, answer = deque(priorities), [], 1
while queue:
max_num = max([data for _, data in queue])
index, data = queue.popleft()
if data == max_num:
relocation.append([index, data])
else:
queue.append([index, data])
for data in relocation:
if data == priorities[location]:
break
else:
answer += 1
return answer
if __name__ == '__main__':
print(solution([2, 1, 3, 2], 2))
print(solution([1, 1, 9, 1, 1, 1], 0))
결과
출처 & 깃허브
programmers 프린터
github