Find Median from Data Stream LeetCode solution in C++
1class MedianFinder {2public:3/* Implemented @StefanPochmann's Incridible Idea */4priority_queue<long long> small, large;5MedianFinder() {}67void addNum(int num) {8small.push(num); // cool three step trick9large.push(-small.top());10small.pop();11while (small.size() < large.size()) {12small.push(-large.top());13large.pop();14}15}1617double findMedian() {18return small.size() > large.size() ? small.top() : (small.top() - large.top()) / 2.0;19}20};