标签:over tps 大顶堆 style double 最大 util solution bsp
我的代码
import java.util.*; public class Solution { PriorityQueue<Integer> min=new PriorityQueue<>(); PriorityQueue<Integer> max=new PriorityQueue<>(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2.compareTo(o1); } }); int count=0; public void Insert(Integer num) { count++; if(count % 2 != 0){ //奇数 max.offer(num); min.offer(max.poll()); }else { min.offer(num); max.offer(min.poll()); } } public Double GetMedian() { if(count % 2 != 0){ return 1.0*min.peek(); }else { return (min.peek() + max.peek())/2.0; } } }
标签:over tps 大顶堆 style double 最大 util solution bsp
原文地址:https://www.cnblogs.com/nlw-blog/p/12482784.html