YulongW
9/11/2017 - 8:39 PM

Java API Examples

/* 
 * Reference:
 *   - https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html
 */

// use Comparator
PriorityQueue<Node> pq = new PriorityQueue<Node>(new Comparator<Node>() {
  @Override
  public int compare(Node n0, Node n1) {
    return n0.val - n1.val;
  }
});

// use Lambda
PriorityQueue<Node> pq = new PriorityQueue<Node>((n0, n1) -> n0.val - n1.val);