[python] 최소힙, 최대힙 - heapq
import문 import heapq 최소힙 minheap = [] heapq.heappush(minheap, 1) heapq.heappush(minheap, 2) heapq.heappush(minheap, 3) print(minheap) # [1,2,3] minheap[0]# 1 heapq.heappop(minheap) # 1 heapq.heappop(minheap) # 2 heapq.heappop(minheap) # 3 최대힙 maxheap = [] heapq.heappush(maxheap, -1) heapq.heappush(maxheap, -2) heapq.heappush(maxheap, -3) print(maxheap) # [-3,-2,-1] maxheap[0] # -3 -heapq.heappop..
2022. 7. 7.