This problem is really uncomfortable, because the new mouse bought yesterday is too insensitive, the click feeling is too bad, affecting the train of thought.

Diss real name ray pa’s mouse, really chicken ribs, do not buy!

It has been returned!!

And get:

Merges two ascending lists into a new ascending list and returns. A new list is formed by concatenating all the nodes of a given two lists.

Example 1:

Input: l1 = [1,2,4], l2 = [1,3,4]Copy the code

Example 2:

Input: L1 = [], L2 = [] output: []Copy the code

Example 3:

Input: L1 = [], L2 = [0] output: [0]Copy the code

Answer key

We can reduce this question to a one-word question:

Next and L2. We just need to compare the values of L1.next and L2. Insert the smaller one after L1, and we’re done.

Therefore, what we need to do every time is to extract the current node and conduct the mergeTwoLists question with the other two nodes as parameters.

var mergeTwoLists = function(l1, l2) { if(l1 === null){ return l2; }else if(l2 === null){ return l1; } if(l1.val < l2.val) { l1.next = mergeTwoLists(l1.next, l2); return l1; } else { l2.next = mergeTwoLists(l1, l2.next); return l2; }};Copy the code

Leetcode-cn.com/problems/me…