import heapqclassMedianFinder:def__init__(self):""" initialize your data structure here. """ self.max_heap = [] self.min_heap = [] heapq.heapify(self.max_heap) heapq.heapify(self.min_heap)defaddNum(self,num:int) ->None:ifnot self.max_heap or num <-self.max_heap[0]: heapq.heappush(self.max_heap, -num)else: heapq.heappush(self.min_heap, num)iflen(self.max_heap)>len(self.min_heap): heapq.heappush(self.min_heap, -heapq.heappop(self.max_heap))iflen(self.max_heap)<len(self.min_heap): heapq.heappush(self.max_heap, -heapq.heappop(self.min_heap))deffindMedian(self) ->float:iflen(self.max_heap)>len(self.min_heap):returnfloat(-self.max_heap[0])eliflen(self.max_heap)<len(self.min_heap):returnfloat(self.min_heap[0])else:returnfloat(self.min_heap[0] +-self.max_heap[0])/2# Your MedianFinder object will be instantiated and called as such:# obj = MedianFinder()# obj.addNum(num)# param_2 = obj.findMedian()