← 返回 meta 的题目列表Find Median from Data Stream Variant
类型:online_judge
Given a stream of floating numbers inserted by binary search insertion, how do you implement an efficient algorithm to find the median in real-time?
Input
Calling the function MedianFinder.addNum(int num) will add an integer num to the data structure.
Output
The function MedianFinder.findMedian() returns the median so far.
Example
After adding numbers [1, 2, 3, 4], the returned medians are [1, 1.5, 2, 2.5] respectively.
Constraints
All elements will be stored in memory, ensuring that the data stream does not get too large.
Example
Input
1
2
3
4