@@ -0,0 +1,1161 @@
+/**%0A * Definition for singly-linked list.%0A * public class ListNode %7B%0A *     int val;%0A *     ListNode next;%0A *     ListNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A  private ListNode merge2Lists(ListNode l1, ListNode l2) %7B%0A    ListNode head = new ListNode(1);%0A    ListNode tail = head;%0A    while (l1 != null && l2 != null) %7B%0A      if (l1.val %3C l2.val) %7B%0A        tail.next = l1;%0A        l1 = l1.next;%0A      %7D else %7B%0A        tail.next = l2;%0A        l2 = l2.next;%0A      %7D%0A      tail = tail.next;%0A    %7D%0A    tail.next = (l1 == null) ? l2 : l1;%0A    return head.next;%0A  %7D%0A%0A  private ListNode partition(ListNode%5B%5D lists, int start, int end) %7B%0A    if (start %3E end) return null;%0A    if (start == end) return lists%5Bstart%5D;%0A    int mid = (start + end) / 2;%0A    ListNode l1 = partition(lists, start, mid);%0A    ListNode l2 = partition(lists, mid + 1, end);%0A    return merge2Lists(l1, l2);%0A  %7D%0A%0A  // Idea is to use previous solution for merging 2 lists and apply divide-and-conquer technique%0A  // by using partitioning. Problem becomes similar to mergesort.%0A  public ListNode mergeKLists(ListNode%5B%5D lists) %7B%0A    return partition(lists, 0, lists.length - 1);%0A  %7D%0A%7D%0A

add solution