Search
Duplicate

이중우선순위큐

문제 설명 및 제한사항

아이디어 및 해결 방법

코드

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()]
Python
복사

출처

프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges