在Python中最大堆实现使用什么? [英] What do I use for a max-heap implementation in Python?
本文介绍了在Python中最大堆实现使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
最简单的方法是反转键的值,使用heapq。例如,将1000.0转换为-1000.0,将5.0转换为-5.0。
Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?
解决方案
The easiest way is to invert the value of the keys and use heapq. For example, turn 1000.0 into -1000.0 and 5.0 into -5.0.
这篇关于在Python中最大堆实现使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文