Share my java solution logn to insert, O(1) to query
Not sure why it is marked as hard, i think this is one of the easiest questions on leetcode.\n\n    class MedianFinder {\n        // max queue is always larger 
Not sure why it is marked as hard, i think this is one of the easiest questions on leetcode.\n\n    class MedianFinder {\n        // max queue is always larger or equal to min queue\n        PriorityQueue<Integer> min = new PriorityQueue();\n        PriorityQueue<Integer> max = new PriorityQueue(1000, Collections.reverseOrder());\n        // Adds a number into the data structure.\n        public void addNum(int num) {\n            max.offer(num);\n            min.offer(max.poll());\n            if (max.size() < min.size()){\n                max.offer(min.poll());\n            }\n        }\n    \n        // Returns the median of current data stream\n        public double findMedian() {\n            if (max.size() == min.size()) return (max.peek() + min.peek()) /  2.0;\n            else return max.peek();\n        }\n    };
['Heap (Priority Queue)', 'Java']