My C# solution using recursive loop


  • 0
    E
    public ListNode MergeTwoLists(ListNode l1, ListNode l2) {
            if (l1 == null)
                return l2;
            if (l2 == null)
                return l1;
            ListNode node, another;
            if (l1.val <= l2.val)
            {
                node = l1;
                another = l2;
            }
            else{
                node = l2;
                another = l1;
            }
            node.next = MergeTwoLists(node.next, another);
            return node;
        }
    

Log in to reply
 

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