해결포인트✨
1. while 문을 돌며 큐 제일 앞의 요소를 꺼낸 후, 프린트 할 건지 말 건지 결정하고 프린트하거나 제일 뒤로 보냈다.
2. 프린트 여부를 결정할 때, 또 for문을 돌면서 확인하면 시간복잡도가 커지기 때문에 set을 활용해 tmp보다 priority가 높은 요소가 존재하는지 확인했다.
코드✨
def solution(priorities, location):
printer = [i for i in range(len(priorities))]
answer = 0
while (location in printer)==True:
tmp = priorities.pop(0)
if len(set(priorities)-set(range(tmp+1)))==0:
# print("중요도 더 높은 요소 없음. 인쇄해도됨")
answer+=1
printer.pop(0)
else:
# print("있음. 뒤로 보내야함")
priorities.append(tmp)
indice = printer.pop(0)
printer.append(indice)
return answer
'코딩테스트 준비' 카테고리의 다른 글
[Greedy] 프로그래머스 - 구명보트 (0) | 2022.08.09 |
---|---|
[큐] 프로그래머스 - 기능개발 (0) | 2022.08.09 |
[큐] 프로그래머스 - 다리를 지나는 트럭 (0) | 2022.08.08 |
[스택] 프로그래머스 - 주식가격 (0) | 2022.08.08 |
[스택] 프로그래머스 - 올바른 괄호 (0) | 2022.08.08 |