Skip to content

Instantly share code, notes, and snippets.

@jonathanagustin
Last active May 2, 2020 12:17
Show Gist options
  • Select an option

  • Save jonathanagustin/3b7405119550a49809f95c865dbaecf7 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanagustin/3b7405119550a49809f95c865dbaecf7 to your computer and use it in GitHub Desktop.
Python Max Heap
import heapq
class Neg():
def __init__(self, x):
self.x = x
def __cmp__(self, other):
return -cmp(self.x, other.x)
def maxheappush(heap, item):
heapq.heappush(heap, Neg(item))
def maxheappop(heap):
return heapq.heappop(heap).x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment