21. Merge Two Sorted Lists
2016-07-26 19:35
274 查看
21. Merge Two Sorted Lists
Leetcode link for this questionDiscription:
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.Analyze:
Code 1 :
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def mergeTwoLists(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ head=ListNode(0) tail=head while l1 and l2: if l1.val > l2.val: tail.next=l2 l2=l2.next else: tail.next=l1 l1=l1.next tail=tail.next if l1 is None: tail.next=l2 else: tail.next=l1 return head.next
Submission Result:
Status: AcceptedRuntime: 52 ms
Ranking: beats 97.5%
相关文章推荐
- quartz动态定时任务
- HDU 2141 Can you find it?(二分)
- 20. Valid Parentheses
- DDR Layout Guide-DDR内存布线指导
- hdu_5761_Rower Bo(xjb猜公式)
- 大数小数的加法
- 【Window编程】Step.1 我的第一个Windows程序
- 14. Longest Common Prefix
- 命令的查看帮助 和 命令行的历史
- Material Design的其他使用
- 13. Roman to Integer
- UVALive - 2701 Find The Multiple
- 阅一道简单程序,了解多线程编程;
- drop table中cascade的含义及用法
- 7. Reverse Integer
- Dynamics CRM 2016 修改服务器名字
- [SCU4437] Carries [2015 Sichuan Province Contest Final B]
- 6. ZigZag Conversion
- Linux-(C)多线程学习(入门)
- 弹性ListView