题解 | 数据流中的中位数
from re import L
# -*- coding:utf-8 -*-
class Solution:
def __init__(self) -> None:
self.List = []
def Insert(self, num):
# write code here
self.List.append(num)
self.List.sort()
def GetMedian(self):
# write code here
lenth = len(self.List)
if lenth % 2 ==0:
index_1 = lenth //2
index_2 = (lenth //2) -1
output = (self.List[index_1] + self.List[index_2]) /2
return output
elif lenth % 2 == 1:
index = lenth//2
return self.List[index]
无语了我真是
三奇智元机器人科技有限公司公司福利 70人发布
