title: "[프로그래머스] 이중우선순위큐 Python 파이썬 해설 (Level 3) - 이도훈"
cleanUrl: "programmers/42628"
description: "프로그래머스 Level 3 문제 [이중우선순위큐]의 풀이를 정리합니다."
from queue import PriorityQueue
from collections import Counter
def solution(operations):
min_heap, max_heap = PriorityQueue(), PriorityQueue()
cnt = 0
for operation in operations:
op, value = operation.split()
value = int(value)
if op == 'I':
cnt += 1
min_heap.put(value)
max_heap.put(-value)
elif cnt > 0:
if value == 1:
if cnt == 1:
min_heap, max_heap = PriorityQueue(), PriorityQueue()
else:
max_heap.get()
cnt -= 1
else:
if cnt == 1:
min_heap, max_heap = PriorityQueue(), PriorityQueue()
else:
min_heap.get()
cnt -= 1
if cnt == 0:
return [0, 0]
else:
return [-max_heap.get(), min_heap.get()]
프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges