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

数据流中的中位数

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

# -*- coding:utf-8 -*-
class Solution:
    l = []
    def Insert(self, num):
        # write code here
        self.l.append(num)
    def GetMedian(self):
        # write code here
        self.l.sort()
        if len(self.l)%2==1:
            return self.l[int(len(self.l)/2-0.5)]
        else:
            return 0.5*(self.l[int(len(self.l)/2-1)] + self.l[int(len(self.l)/2)])

全部评论

相关推荐

投递拓竹科技等公司10个岗位
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
07-19 13:28
长沙学院 Java
程序员小白条:你有面试就有希望,没面试自然就没希望,到时候就知道了,你问别人也没啥用处的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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