方式一 调用 comparator.reverseOrder () 方法
PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
方式二 Override comparator#
PriorityQueue pq = new PriorityQueue<>(new Comparator<Integer>() {
@Override
public int compare(Integer a, Integer b) {
return b - a;
}
});
方式三 Lamda 表达式
PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> b - a);