[LeetCode] Merge Two Sorted Lists
2015-08-18 17:03
239 查看
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来辅助,这种思路更为常见,不过简化后就发现不需要新建啦~
代码如下。~
这道题还是很有意思的><个人觉得题读懂后就没啥难的了。
当然这里其实也还可以另外新弄一个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; } } }
相关文章推荐
- unity批量获取物体组件修改值,拓展子物体查询
- Solrj API读取core 索引库数据
- cgi 编程的get和post
- 4.3.4、registry配置参考
- IOCP相关的一些总结
- 程序员面试宝典(第4版) 欧立奇 学习笔记
- 1088. Rational Arithmetic (20)
- 多校 9
- 颜色代码查询,在线颜色选择器,RGB颜色对照表
- 建物化视图日志报索引未发现ORA-08102
- redis主从服务器的配置(入门)
- 多校第九场 1005 hdu 5400 Arithmetic Sequence ( dp)
- Cloudstack 安装记录
- UvA 12661 Funny Car Racing (最短路)
- mysql数据库,删除root用户后恢复
- i+1问题
- 【转】15个必须知道的chrome开发者技巧
- sed命令
- Android 调用已安装市场,进行软件评分的功能实现
- JavaScript 对象