合并两个排序的链表 Posted on 2019-08-19 | In 剑指offer | | reads times 合并两个排序的链表题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。 递归做法 123456789101112131415function Merge(pHead1, pHead2){ // write code here let pmergehead=null; if(pHead1===null) return pHead2; if(pHead2===null) return pHead1; if(pHead1.val<pHead2.val){ pmergehead=pHead1; pmergehead.next=Merge(pHead1.next,pHead2); }else{ pmergehead=pHead2; pmergehead.next=Merge(pHead1,pHead2.next); } return pmergehead;} Post author: GoldMiner Xun Post link: https://goldminerxun.github.io/2019/08/19/%E5%89%91%E6%8C%87offer%20JavaScript%E7%89%88%20(16)/ Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.