参考文章
https://leetcode-cn.com/problems/find-median-from-data-stream/solution/shu-ju-liu-de-zhong-wei-shu-by-leetcode/
一般思路:在push的时候进行排序。
或者:用一个最大堆和最小堆来时刻更新堆顶的元素(即中位数)
或者:使用AVL树,用2个指针时刻更新中位数的位置。
力扣295-数据流的中位数
最新推荐文章于 2022-05-15 23:22:04 发布
参考文章
https://leetcode-cn.com/problems/find-median-from-data-stream/solution/shu-ju-liu-de-zhong-wei-shu-by-leetcode/
一般思路:在push的时候进行排序。
或者:用一个最大堆和最小堆来时刻更新堆顶的元素(即中位数)
或者:使用AVL树,用2个指针时刻更新中位数的位置。