剑指offer python版 数据流中的中位数

import heapq
import math
def aa(nums):
    mid=math.ceil(len(nums)/2)
    q=heapq.nlargest(mid,nums)[-1]
    m=heapq.nsmallest(mid,nums)[-1]    
    
    return (m+q)/2


print(aa([1,2,3,3,4,5]))

 

posted @ 2018-10-26 15:43  findtruth123  阅读(600)  评论(0)    收藏  举报