Day 44: force buckle problem 21, merge two ordered linked lists
Address: leetcode-cn.com/problems/me…
Idea: is to judge the splicing, mainly is the use of linked list
var mergeTwoLists = function(l1, l2) { if(l1 === null) { return l2; } else if(l2 === null) { return l1; } else if(l1.val < l2.val) { l1.next = mergeTwoLists(l1.next, l2); l2 = null; return l1; } else { l2.next = mergeTwoLists(l2.next, l1); l1 = null; return l2; }};Copy the code
Execution time: 92 ms, beating 78.94% of all JavaScript commits
Memory consumption: 39.5 MB, beating 19.12% of all JavaScript commits