another simple,easy solution with Java


  • 0
    B

    public class Solution {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
    if(l1==null)
    return l2;
    if(l2==null)
    return l1;
    ListNode newHead = l1.val < l2.val ? l1 : l2;
    ListNode max= l1.val < l2.val ? l2 : l1;
    newHead.next = mergeTwoLists(newHead.next,max);
    return newHead;
    }
    }


Log in to reply
 

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