알고리즘/프로그래머스
[프로그래머스] 이중우선순위큐
컴공0개언어
2021. 6. 20. 18:33
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42628
코딩테스트 연습 - 이중우선순위큐
programmers.co.kr
문제에 주어진대로 그대로 코드를 작성하면 해결되는 문제였다.
import heapq
def solution(operations):
# len(operations) : 1 <= n <= 10000000
answer = []
heap = []
for operation in operations:
op = operation.split()[0]
data = operation.split()[1]
if op == 'I':
heapq.heappush(heap, int(data))
elif op == 'D' and len(heap) > 0:
if data == '1':
heap.pop()
elif data == '-1':
heapq.heappop(heap)
if len(heap) > 0:
answer = [max(heap), min(heap)]
else:
answer = [0, 0]
return answer