(Java) Easy Divide & Conquer Method with the mergeTwoLists helper method


  • 0

    '''

    public ListNode mergeKLists(ListNode[] lists) {
        if (lists.length == 0) return null;
        if (lists.length == 1) return lists[0];
        ListNode sublist1 = mergeKLists(Arrays.copyOfRange(lists, 0, lists.length / 2)); 
        ListNode sublist2 = mergeKLists(Arrays.copyOfRange(
                                        lists, lists.length / 2, lists.length));
      
        return mergeTwoLists(sublist1, sublist2);
    }
    

    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.