[Python] 1927 최소 힙 - 실버2

Saemi Min·2023년 3월 31일
0

BaekJoon

목록 보기
28/30
post-thumbnail

문제

해당 문제 링크

정답

## 최소 힙

import heapq
import sys
input=sys.stdin.readline

n=int(input())

h=[]
for i in range(n):
    x=int(input())
    if x==0:
        if len(h)==0:
            print(0)
        else:
            print(heapq.heappop(h))
    else:
        heapq.heappush(h, x)
    

문법

힙(Heap) 문법을 작성해 놓은 해당 사이트를 참고하면 이해하기 쉽다

profile
I believe in myself.

0개의 댓글