Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 我在 Python 中使用什么来实现最大堆?
Python 在 heapq 模块中实现了一个最小堆。但是,如果想要一个最大堆,是否必须从头开始构建?
您可以将数字乘以 -1 并使用最小堆。
无需从头开始实现最大堆。您可以轻松地使用一些数学来将您的最小堆变成最大堆!
看到这个和这个- 但真的是这个 SO 答案。