第四十四天:力扣第21题,合并两个有序链表
地址:leetcode-cn.com/problems/me…
思路:就是判断拼接,主要是链表的使用
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;
}
};
执行用时:92 ms, 在所有 JavaScript 提交中击败了78.94%的用户
内存消耗:39.5 MB, 在所有 JavaScript 提交中击败了19.12%的用户