北地还是武地啊,链表可以用头插法 var mergeTwoLists = function(l1, l2) { let dummy = new ListNode(-1); while(l1 &;&; l2){ let temp = dummy.next; if(l1.val < l2.val){ dummy.next = l1; l1 = l1.next; }else{ dummy.next = l2; l2 = l2.next; } dummy.next.next = temp; } while(l1){ let temp = dummy.next; dummy.next = l1; l1 = l1.next; dummy.next.next = temp; } while(l2){ let temp = dummy.next; dummy.next = l2; l2 = l2.next; dummy.next.next = temp; } return dummy.next; };
2 1

相关推荐

牛客网
牛客企业服务