public ListNode mergeKLists(List<ListNode> lists) {
            while (lists.contains(null)) {
                lists.remove(null);
            }
            if (lists.size() == 0) {
                return null;
            }
            if (lists.size() == 1) {
                return lists.get(0);
            }
            ListNode dummy = new ListNode(-1);
            ListNode next = dummy;
            ListNode l1 = lists.get(0);
            for (int i = 1; i < lists.size(); i++) {
                ListNode l2 = lists.get(i);
                while (l1 != null && l2 != null) {
                    if (l1.val > l2.val) {
                        next.next = l2;
                        l2 = l2.next;
                    } else {
                        next.next = l1;
                        l1 = l1.next;
                    }
                    next = next.next;
                }
                next.next = l1 == null ? l2 : l1;
                l1 = dummy.next;
                if (i < lists.size() - 1) {
                    dummy = new ListNode(-1);
                    next = dummy;
                }
            }
            return dummy.next;
        }