class Solution { public ListNode mergeKLists(ListNode[] lists) { if(lists == null || lists.length == 0){ return null; } if(lists.length == 1){ return lists[0]; } return split(lists, 0, lists.length-1); } public ListNode split(ListNode[] lists, int left, int right){ if(left == right){ return lists[left]; } int mid = left + (right-left)/2; return mergeTwoLists(split(lists, left, mid), split(lists, mid+1, right)); } public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if(l1 == null){ return l2; } if(l2 == null){ return l1; } ListNode head = null; ListNode tmp = null; if(l1.val <= l2.val){ tmp = l1; head = l1; l1 = l1.next; } else { tmp = l2; head = l2; l2 = l2.next; } while(l1!=null && l2!=null){ if(l1.val <= l2.val){ tmp.next = l1; l1 = l1.next; } else { tmp.next = l2; l2 = l2.next; } tmp = tmp.next; tmp.next = null; } if(l1 != null){ tmp.next = l1; } if(l2 != null){ tmp.next = l2; } return head; }}