merge sort

public class Solution {

public ListNode mergeKLists(ListNode[] lists) {

if(lists==null || lists.length==0) return null;

return helper(lists,0,lists.length-1);

}

public ListNode helper(ListNode[] lists, int s, int e){

if(s==e)

return lists[s];

int m=(s+e)/2;

return merge(helper(lists,s,m),helper(lists,m+1,e));

}

}

Last updated

Was this helpful?