295. Find Median from Data Stream
295. Find Median from Data Stream
Description
Solution
Because we are handling a stream problem, if we need resort the array each time it is a costy solution. So if we could have a self-balance binary search tree, we could use the top of the tree as the answer, but just writing a AVL or RBT is not very troublesome. A better solution is to use two priority queue, one is min heap and other is max heap.
Code
1 | class MedianFinder { |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.