brute force method


  • 0
    S

    public ListNode mergeKLists(ListNode[] lists) {
    if(lists==null) {
    return null;
    }
    ArrayList<Integer> resultList = new ArrayList<>();
    for(ListNode ln:lists) {
    while(ln!=null) {
    resultList.add(ln.val);
    ln=ln.next;
    }
    }
    Collections.sort(resultList);
    ListNode ans = new ListNode(0);
    ListNode head = ans;
    for(int temp:resultList) {
    ans.next = new ListNode(temp);
    ans=ans.next;
    }

    	return head.next;
    

    }


Log in to reply
 

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