#leetcode 021 Merge Two Sorted Lists(Python)
来源:互联网 发布:手游英雄杀十连抽数据 编辑:程序博客网 时间:2024/05/17 22:08
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.
将两个排好序的链表拼接成一个新的链表
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: # @param {ListNode} l1 # @param {ListNode} l2 # @return {ListNode} def mergeTwoLists(self, l1, l2): if l1 == None: return l2 if l2 == None: return l1 if l1.val>l2.val: temp = l2 l2 = l1 l1 = temp l = l1 while l2 != None: if l1.next==None: l1.next = l2 break if l1.next.val > l2.val: temp = l1.next l1.next = l2 l2 = l2.next l1 = l1.next l1.next = temp else: l1 = l1.next return l
0 0
- #leetcode 021 Merge Two Sorted Lists(Python)
- 【LeetCode with Python】 Merge Two Sorted Lists
- [leetcode:python]21.Merge Two Sorted Lists
- Leetcode-Merge Two Sorted Lists-Python
- 【Leetcode】【python】Merge Two Sorted Lists
- 【LeetCode 21】Merge Two Sorted Lists(Python)
- LeetCode 021 Merge Two Sorted Lists
- LeetCode 021 Merge Two Sorted Lists
- 【LeetCode OJ 021】Merge Two Sorted Lists
- 021 Merge Two Sorted Lists [Leetcode]
- LeetCode 021 Merge Two Sorted Lists
- [LeetCode]021-Merge Two Sorted Lists
- leetcode 021 Merge Two Sorted Lists
- LeetCode 021 Merge Two Sorted Lists
- LeetCode 021 Merge Two Sorted Lists
- LeetCode-021 Merge Two Sorted Lists
- Merge Two Sorted Lists(LeetCode)
- LeetCode(21)Merge Two Sorted Lists
- greenplum中对单个节点备份并进行串行恢复
- 2015-06-12 五-翻转二叉树
- 【译】Python中如何创建mock?
- u-boot-2012.04.01移植笔记——支持NAND启动
- Storyboard Reference
- #leetcode 021 Merge Two Sorted Lists(Python)
- Mini2440加载模块时遇到错误几个问题
- 文顶顶 iOS开发UI篇—手写控件,frame,center和bounds属性 iOS开发UI基础—手写控件,frame,center和bounds属性
- C、C++一次将整个文件读入内存
- 更改源泉书签的重要性显示
- MySQL 数据库备份 和字段更改
- ubuntu14.04 iBUS拼音输入法无法使用全拼
- 毕业论文从0到完成获得东西
- 修复windows installer安装错误