import { ListNode } from '../LinkList/LinkList' ; param { ListNode } lists return { ListNode } function MergeKList ( lists ) { let len = lists . length ; if ( len < 3 ) { return merge ( lists [ 0 ] || null , lists [ 1 ] || null ) ; } else { let mid = len >> 1 ; return merge ( MergeKList ( lists . slice ( 0 , mid + 1 ) ) , MergeKList ( lists . slice ( mid + 1 ) ) ) ; } } param { ListNode } list1 param { ListNode } list2 return { ListNode } function merge ( list1 , list2 ) { if ( list1 === null || list2 === null ) { return list1 ? list1 : list2 ; } let root = null ; let pointer = null ; if ( list1 . val <= list2 . val ) { pointer = list1 ; list1 = list1 . next ; } else { pointer = list2 ; list2 = list2 . next ; } root = pointer ; while ( list1 !== null && list2 !== null ) { if ( list1 . val <= list2 . val ) { pointer . next = list1 ; list1 = list1 . next ; } else { pointer . next = list2 ; list2 = list2 . next ; } pointer = pointer . next ; } if ( list1 !== null ) { pointer . next = list1 ; } else { pointer . next = list2 ; } return root ; } export { MergeKList } ;