大顶堆:
//其中map为全局变量 PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>( public int comapre(Integer a, Integer b){ return map.get(b) - map.get(a); } ));
小顶堆:
//其中map为全局变量 PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() { @Override public int compare(Integer a, Integer b) { return map.get(a) - map.get(b); } });
PriorityQueue<ListNode> pq = new PriorityQueue<>((x,y) -> (x.val - y.val));
PriorityQueue<Integer> pq = new PriorityQueue<>((x,y) -> (x - y));