21. Merge Two Sorted Lists
2016-02-28 22:47
337 查看
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.
AC代码:
因为都是有序的链表,直接按照大小遍历即可。
AC代码:
class Solution(object): def mergeTwoLists(self, l1, l2): ret_list = current = ListNode(0) while l1 is not None and l2 is not None: if l1.val <= l2.val: current.next = l1 l1 = l1.next else: current.next = l2 l2 = l2.next current = current.next if l1 is not None: current.next = l1 if l2 is not None: current.next = l2 return ret_list.next
因为都是有序的链表,直接按照大小遍历即可。
相关文章推荐
- UIView属性clipsTobounds的应用
- OA学习笔记-008-岗位管理Action层实现
- 使用JS实现RTMP协议直播(三)
- Toolbar使用方法
- HOJ-2056 Bookshelf(线性动态规划)
- ACM_模板_并查集
- HOJ-2056 Bookshelf(线性动态规划)
- 调查问卷
- Spiral Matrix II
- 3-9-模拟银行排队过程-栈和队列-第3章-《数据结构》课本源码-严蔚敏吴伟民版
- mktime的使用
- Android性能优化——优化下载以高效地访问网络
- ROS学习--轻松使用tf
- WPF中的DataGrid的RowDetail显示问题
- C语言字符串操作总结大全(超详细)
- 【MySQL】探究之TIMESTAMP
- linux内核分析第一周学习笔记
- 关于 adjustsFontSizeToFitWidth 的使用
- 第三次作业
- 分享在winform下实现左右布局多窗口界面-续篇