题解 | #数据流中的中位数#

数据流中的中位数

https://www.nowcoder.com/practice/9be0172896bd43948f8a32fb954e1be1

using System.Collections.Generic;

class Solution {
    List<int> list = new List<int>();
    public void Insert(int num) {
        // write code here
        int nFI = list.FindIndex(r => r > num);
        if (nFI > -1)
            list.Insert(nFI, num);
        else
            list.Add(num);
    }

    public double GetMedian() {
        // write code here
        int nM = list.Count / 2;
        if (list.Count % 2 == 0)
            return (list[nM] + list[nM - 1]) / 2.0;
        else
            return list[nM];
    }
}

全部评论

相关推荐

Gaynes:查看图片
点赞 评论 收藏
分享
湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 10:39
一个证都没&nbsp;我能填什么
程序员小白条:别人有,你为什么没有,还是这个道理,社会就是比较,竞争,淘汰,你要安逸,那么就要做好淘汰的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务