leetcode-295-Find Median from Data Stream

本文探讨了使用两个堆(左堆和右堆)来维护数据流中位数的方法,并介绍了二叉搜索树(BST)及其在处理奇偶数变化时的应用。通过对不同情况的分析,展示了如何在数据结构中高效地保持中位数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

error:
cannot slove it.

  1. Use two heap, first the keep store left half and other for right heap. And 0 <= |left.size() - right| <= 1. If violent the rule, move to top number to other side. If current num larger than left.top(), push to right, otherwise push to left.

  2. Use BST, and multiset is implement of BST. We have 4 case:

    odd -> even

    • num < r: l–
    • num >= r: r++
      even ->odd
    • num < r: r–, l = r
    • num >= r: l = r
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值