4
### max heap to store the first half of the list6
### min heap to store the second half of the list9
def addNum(self, num: int) -> None:10
### push num into the correct heap11
if not self.maxHeap or num <= -self.maxHeap[0]:12
heappush(self.maxHeap, -num)14
heappush(self.minHeap, num)16
### banance the two heaps so that each of them representing half of the list17
### for odd length list, len(maxHeap) == len(minHeap)+118
### for even length list, len(maxHeap) == len(minHeap)19
if len(self.minHeap) > len(self.maxHeap):20
heappush(self.maxHeap, -heappop(self.minHeap))21
elif len(self.maxHeap) > len(self.minHeap) + 1:22
heappush(self.minHeap, -heappop(self.maxHeap))24
def findMedian(self) -> float:26
### if the length of entire list is even,27
### get the mean of the two middle values28
if (len(self.maxHeap) + len(self.minHeap)) % 2 == 0:29
return (-self.maxHeap[0] + self.minHeap[0]) / 231
### when odd, we know that the median is in maxHeap32
return -self.maxHeap[0]