본문 바로가기

python

파이썬에서 heapq로 최소 힙 - 우선순위 큐 구현

import sys
import heapq
n = int(input())
arr = []
for i in range(n):
command = int(sys.stdin.readline().rstrip())
if command != 0:
heapq.heappush(arr, command)
else:
if arr:
print(heapq.heappop(arr))
else:
print(0)

 

'python' 카테고리의 다른 글

이런식으로도 문자열 만들 수 있다  (0) 2021.03.03
파이썬으로 현재 시간 출력하기 - datetime  (0) 2021.02.27
list.pop(index)  (0) 2021.02.23
* 출력  (0) 2021.02.22
set()  (0) 2021.02.09