Day 103heapqで優先度付きキュー

2026-06-07 JST ・ 難易度: 中級 ・ カテゴリ: 標準ライブラリ

Pythonコード

1import heapq2numbers = [4, 2, 9, 6, 5, 1, 8, 3, 7]3print("元のリスト: ", numbers)4heapq.heapify(numbers)5print("ヒープ化したリスト: ", numbers)6print("最小値: ", heapq.heappop(numbers))7print("次の最小値: ", heapq.heappop(numbers))

解説

次に試してみよう