public static ListNode mergeKLists(List<ListNode> lists) {
        if(lists.size() == 0) return null;

        Comparator<ListNode> comparator = new Comparator<ListNode>() {
            @Override
            public int compare(ListNode o1, ListNode o2) {
                return o1.val - o2.val;
            }
        };

        PriorityQueue<ListNode> queue = new PriorityQueue<ListNode>(lists.size(), comparator);
        for(ListNode node : lists){
            if(node != null) queue.offer(node);
        }

        ListNode dummy = new ListNode(-1);
        ListNode dummyHead = dummy;
        while(!queue.isEmpty()){
            ListNode node = queue.poll();
            dummy.next = node;
            if(node.next != null) queue.offer(node.next);
            dummy = dummy.next;
        }
        return dummyHead.next;
    }