@@ -0,0 +1,1033 @@
+public class MedianFinder %7B%0A  PriorityQueue%3CInteger%3E minHeap;%0A  PriorityQueue%3CInteger%3E maxHeap;%0A%0A  /** initialize your data structure here. */%0A  public MedianFinder() %7B%0A    minHeap = new PriorityQueue%3CInteger%3E(11, Collections.reverseOrder());%0A    maxHeap = new PriorityQueue%3CInteger%3E(11);%0A  %7D%0A%0A  public void addNum(int num) %7B%0A    if (maxHeap.isEmpty()) %7B%0A      maxHeap.add(num);%0A    %7D else if (maxHeap.peek() %3C= num) %7B%0A      maxHeap.add(num);%0A      if (maxHeap.size() %3E minHeap.size() + 1) %7B%0A        minHeap.add(maxHeap.poll());%0A      %7D%0A    %7D else %7B%0A      minHeap.add(num);%0A      if (minHeap.size() %3E maxHeap.size()) %7B%0A        maxHeap.add(minHeap.poll());%0A      %7D%0A    %7D%0A  %7D%0A%0A  public double findMedian() %7B%0A    if (maxHeap.isEmpty()) return 0.0;%0A    return maxHeap.size() == minHeap.size() ? (maxHeap.peek() + minHeap.peek()) / 2.0 : maxHeap.peek();%0A  %7D%0A%7D%0A%0A/**%0A * Your MedianFinder object will be instantiated and called as such:%0A * MedianFinder obj = new MedianFinder();%0A * obj.addNum(num);%0A * double param_2 = obj.findMedian();%0A */%0A

add solution