[LeetCode]题解(python):147-Insertion Sort List
2016-05-10 15:31
639 查看
[b]题目来源:[/b]
https://leetcode.com/problems/insertion-sort-list/
[b]题意分析:[/b]
用插入排序排序一个链表。
[b]题目思路:[/b]
这题没什么好说的,直接用插入排序就行。
[b]代码(python):[/b]
View Code
https://leetcode.com/problems/insertion-sort-list/
[b]题意分析:[/b]
用插入排序排序一个链表。
[b]题目思路:[/b]
这题没什么好说的,直接用插入排序就行。
[b]代码(python):[/b]
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def insertionSortList(self, head): """ :type head: ListNode :rtype: ListNode """ if head == None: return head tmp = ListNode(0) tmp.next,p = head,head while p.next: if p.next.val < p.val: tmp1 = tmp while tmp1.next.val < p.next.val: tmp1 = tmp1.next t = p.next p.next = t.next t.next = tmp1.next tmp1.next = t else: p = p.next return tmp.next
View Code
相关文章推荐
- [LeetCode]题解(python):146-LRU Cache
- Python处理Excel(四):自定义类处理Excel数据
- python面向对象编程基础II(类的继承)
- Python基础篇【第8篇】: Socket编程(二)SocketServer
- Python实现欧拉计划22题
- python 多个关键字替换
- 102. Binary Tree Level Order Traversal [easy] (Python)
- Python详说正则表达式(对常用的关键字符的讲解)
- Python学习笔记:集合(set)基本内容
- [LINK]用Python计算昨天、今天和明天的日期时间
- [LINK]python中的日期和时间格式化输出
- Python:浮点运算的问题与限制
- [LINK]Python MySQLdb 学习总结
- [转]Python 命令行参数和getopt模块详解
- 基于python的百度云网盘资源搜索引擎设计架构
- [LeetCode]题解(python):145-Binary Tree Postorder Traversal
- Python 学习笔记9(装饰器,decorator)
- [LeetCode]题解(python):144-Binary Tree Preorder Traversal
- python 获取局域网内的广播地址
- python 建立ssh连接 并登陆mysql