public ListNode mergeKLists(List<ListNode> lists) {
        Queue<ListNode> queue = new PriorityQueue<ListNode>(10, new Comparator<ListNode>() {
            @Override
            public int compare(ListNode o1, ListNode o2) {
                if(o1.val < o2.val) return -1;
                else if(o1.val > o2.val) return 1;
                else return 0;
            }
        });

        ListNode dummy = new ListNode(0);
		ListNode p = dummy;
        for(ListNode node : lists) {
            if(node != null) queue.offer(node);
        }
        while (!queue.isEmpty()){
            ListNode node = queue.poll();
			p.next = node;
			if(node.next != null) queue.offer(node.next);
			p = p.next;
        }
        return dummy.next;
    }