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

数据流中的中位数

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

# -*- coding:utf-8 -*-


class Solution:
    def __init__(self) -> None:
        self.input_list=[]
    def Insert(self, num):
        # write code here
        self.input_list.append(num)
    def GetMedian(self):
        # write code here
        sort_list=sorted(self.input_list)
        if len(sort_list)%2==0:
            index = int(len(sort_list)/2)
            return (sort_list[index]+sort_list[index-1])/2
        else:
            index = int((len(sort_list)-1)/2)
            return sort_list[index]

暴力解法 后面再更新优化的

全部评论

相关推荐

mq2:我倒是觉得这种敞亮一点好。能接受就去不能就不去呗。 完了跟现在“正常”公司一样,hr说的天花乱坠,进去一看根本就是996核动力牛马,想走又没应届生身份了。岂不是更糟。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务