public ListNode mergeKLists(ListNode[] lists) {
        if (lists == null || lists.length == 0)
            return null;
        PriorityQueue<ListNode> queue = new PriorityQueue<ListNode>(lists.length,
                new Comparator<ListNode>() {
                    @Override
                    public int compare(ListNode o1, ListNode o2) {
                        if (o1 == null) {
                            return 1;
                        } else if (o2 == null)
                            return -1;
                        return o1.val - o2.val;
                    }
                });
        for (ListNode l : lists) {
            if (l != null)
                queue.add(l);
        }
        ListNode dummy = new ListNode(-1);
        ListNode ans = dummy;
        while (queue.isEmpty() == false) {
            ListNode head = queue.poll();
            ans.next = head;
            ans = ans.next;
            if (head.next != null) {
                queue.add(head.next);
            }
        }
        return dummy.next;
    }