【LEETCODE】147- Insertion Sort List [Python]
来源:互联网 发布:linux下的怎么写程序 编辑:程序博客网 时间:2024/05/22 13:01
Sort a linked list using insertion sort.
题意:
用插入排序
参考:
http://bookshadow.com/weblog/2015/01/06/leetcode-insertion-sort-list/
Python:
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def insertionSortList(self, head): """ :type head: ListNode :rtype: ListNode """ if head is None or head.next is None: return head dummy=ListNode(0) dummy.next=head cur=head while cur.next: if cur.val>cur.next.val: pre=dummy while pre.next.val<cur.next.val: pre=pre.next m=cur.next cur.next=m.next m.next=pre.next pre.next=m else: cur=cur.next return dummy.next
0 0
- 【LEETCODE】147- Insertion Sort List [Python]
- LeetCode-Insertion Sort List (Python)
- [leetcode] Insertion Sort List(python)
- Insertion Sort List Leetcode Python
- [Leetcode][python]Insertion Sort List
- LeetCode(147) Insertion Sort List
- LeetCode: Insertion Sort List [147]
- LeetCode 147 Insertion Sort List
- [leetcode 147] Insertion Sort List
- LeetCode 147 Insertion Sort List
- LeetCode 147 Insertion Sort List
- [leetcode 147]Insertion Sort List
- leetcode-147 Insertion Sort List
- [LeetCode 147]Insertion Sort List
- Leetcode[147]-Insertion Sort List
- Insertion Sort List - LeetCode 147
- leetcode[147]:Insertion Sort List
- LeetCode(147) Insertion Sort List
- c# 抗变 协变
- GDKOI2016Day1第二题 不稳定的传送门 解题报告
- GridView常用属性
- mac下mysql中文乱码
- tsinsen A1043. 完美的代价
- 【LEETCODE】147- Insertion Sort List [Python]
- LintCode-删除链表中的元素
- hdoj 2030 汉字统计
- 半年总结——不知怎么形容
- ntellij 查看所有断点 屏蔽断点 点击mute breakPolint
- 以烧录yocto镜像为例--详细解析freescale MFGTools烧录原理
- CALayer 的属性介绍
- CodeForces 612 C. Replace To Make Regular Bracket Sequence(栈)
- XGBoost Windows 下的 安装 使用