星空网 > 软件开发 > Java

[LeetCode] Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

 

     这道题还是很有意思的><个人觉得题读懂后就没啥难的了。

     当然这里其实也还可以另外新弄一个listnode来辅助,这种思路更为常见,不过简化后就发现不需要新建啦~

     代码如下。~     

public class Solution {  public ListNode mergeTwoLists(ListNode l1, ListNode l2) {    if(l1==null&&l2==null){      return null;    }    if(l1==null&&l2!=null){      return l2;    }    if(l2==null&&l1!=null){      return l1;    }    if(l1.val>l2.val){      l2.next=mergeTwoLists(l1,l2.next);      return l2;    }else{      l1.next=mergeTwoLists(l2,l1.next);      return l1;    }  }}

 




原标题:[LeetCode] Merge Two Sorted Lists

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境电商主体超10万家!出海生意凭什么脱颖而出?:https://www.kjdsnews.com/a/1481665.html
询多多对外贸网站推广的建议!:https://www.kjdsnews.com/a/1481666.html
跨境支付解析:支付方式和特点全面解读:https://www.kjdsnews.com/a/1481667.html
facebook群组营销教程:https://www.kjdsnews.com/a/1481668.html
订单下跌一半!卖家:广告费花完仍不出单:https://www.kjdsnews.com/a/1481669.html
一文读懂进口食品进口商备案2023年版:https://www.kjdsnews.com/a/1481670.html
NRA账户的开户主体包括:香港、美国、新加坡、欧盟等国家的详细解析 :https://www.kjdsnews.com/a/1842292.html
NRA账户的开户主体包括:香港、美国、新加坡、欧盟等国家的详细解析 :https://www.xlkjsw.com/news/94338.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流