728x90
from collections import deque
def solution(priorities, location):
answer = 1
q = deque(priorities)
index = location
while len(q)>1 :
pop = q.popleft()
if pop < max(q):
q.append(pop)
if index == 0:
index = len(q) - 1
else:
index -= 1
else:
if index == 0:
return answer
else:
answer += 1
index -= 1
return answer
풀이 및 회고
deque 를 이용해서 우선순위 배열을 큐에 저장합니다. 그 후 우선순위를 비교하면서 우선순위가 낮으면 다시 큐에 넣고 우아니면 큐에서 제외 시킵니다. 그리고 location 즉 index가 0 일때 저희가 찾고 싶은 요소니까 return을 해줍니다.
728x90
'프로그래머스' 카테고리의 다른 글
프로그래머스 LV2 타겟넘버 (1) | 2024.06.02 |
---|---|
프로그래머스 LV2 피로도 (0) | 2024.06.01 |
프로그래머스 LV 2 기능개발 (0) | 2024.05.27 |
프로그래머스 LV2 의상 (0) | 2024.05.27 |
프로그래머스 LV2 [1차] 캐시 (0) | 2024.05.27 |