剑指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]))
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]))