classMedianFinder{private PriorityQueue<Integer> large;private PriorityQueue<Integer> small;/**
* initialize your data structure here.
*/publicMedianFinder(){
large =newPriorityQueue<>();
small =newPriorityQueue<>((a,b)->{return b-a;});}publicvoidaddNum(int num){if(small.size()>= large.size()){
small.offer(num);
large.offer(small.poll());}else{
large.offer(num);
small.offer(large.poll());}}publicdoublefindMedian(){if(large.size()< small.size()){return small.peek();}elseif(large.size()> small.size()){return large.peek();}return(large.peek()+ small.peek())/2.0;}}/**
* Your MedianFinder object will be instantiated and called as such:
* MedianFinder obj = new MedianFinder();
* obj.addNum(num);
* double param_2 = obj.findMedian();
*/