Leetcode 21 Merge Two Sorted Lists
2016-04-07 11:35
197 查看
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.
class Solution(object): def mergeTwoLists(self, l1, l2): p1, p2 = l1, l2 dummy = ListNode(0) p = dummy while p1 and p2: if p1.val <= p2.val: p.next = p1 p1 = p1.next else: p.next = p2 p2 = p2.next p = p.next if p1: p.next = p1 else: p.next = p2 return dummy.next
相关文章推荐
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-002使用@Embeddable
- java中的栈和堆
- C#中数据库连接字符串写入配置文件
- 子类与父类构造器关系
- 使用js把数据保存为csv文件
- 一个简单Ajax类库及使用方法实例分析
- LeetCode111—Minimum Depth of Binary Tree
- JQuery中$.ajax()方法参数详解
- 稀疏表示
- Cmaker 是什么
- HTML5客户端存储之 LocalStorage 和 SessionStorage
- c++作业3
- c++实验3
- 第02篇. Jetty 9 实战之安装/运行/部署
- Swing设置单元格不可编辑
- Andriod基础:RatingBar设置
- Lucene 查询中的距离查询(proximity query)
- MySQL行级锁、表级锁、页级锁详细介绍
- 区间DP总结
- Shiro学习(10)Session管理