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

数据流中的中位数

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]

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

全部评论

相关推荐

notbeentak...:真的nc,算毕业6月份,要给这种b公司打半年多白工😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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