剑指offer-数据流中的中位数(python)

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

猜你喜欢

转载自blog.csdn.net/qq_42738654/article/details/104620275