利用最大堆来求解第k个最大值
首先建立最大堆
PriorityQueue< Integer > maxheap = new PriorityQueue<>( Collections.reverseOrder() );
每次循环删除一个,最后一个元素补至第一个,进行排序,再次在顶点得到最大值。
最小堆:
PriorityQueue< Integer > minheap = new PriorityQueue<>( );
maxheap.add();
maxheap.peek();
maxheap.poll();
maxheap.size();
maxheap.isEmpty();