[LeetCode]题解(python):147-Insertion Sort List
题目来源:
https://leetcode.com/problems/insertion-sort-list/
题意分析:
用插入排序排序一个链表。
题目思路:
这题没什么好说的,直接用插入排序就行。
代码(python):
# 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
[LeetCode]题解(python):147-Insertion Sort List的更多相关文章
- 【LeetCode】147. Insertion Sort List 解题报告(Python)
[LeetCode]147. Insertion Sort List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...
- [LeetCode] 147. Insertion Sort List 链表插入排序
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...
- LeetCode OJ 147. Insertion Sort List
Sort a linked list using insertion sort. Subscribe to see which companies asked this question 解答 对于链 ...
- Java for LeetCode 147 Insertion Sort List
Sort a linked list using insertion sort. 解题思路: 插入排序,JAVA实现如下: public ListNode insertionSortList(List ...
- leetcode 147. Insertion Sort List ----- java
Sort a linked list using insertion sort. 插入排序. /** * Definition for singly-linked list. * public cla ...
- [LeetCode] 147. Insertion Sort List 解题思路
Sort a linked list using insertion sort. 问题:实现单向链表的插入排序. 这是比较常规的一个算法题目. 从左往右扫列表,每次将指针的下一个元素插入前面已排好序的 ...
- 【leetcode】147. Insertion Sort List
Sort a linked list using insertion sort. 链表的插入排序. 需要创建一个虚拟节点.注意点就是不要节点之间断了. class Solution { public: ...
- LeetCode 147. Insertion Sort List 链表插入排序 C++/Java
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...
- [leetcode sort]147. Insertion Sort List
Sort a linked list using insertion sort. 利用插入排序对一个链表进行排序 思路和数组中的插入排序一样,不过每次都要从链表头部找一个合适的位置,而不是像数组一样可 ...
- 【刷题-LeetCode】147 Insertion Sort List
Insertion Sort List Sort a linked list using insertion sort. A graphical example of insertion sort. ...
随机推荐
- Redis系列整理
0.Redis系列-安装部署维护篇 1.Redis系列-远程连接redis并给redis加锁 2.Redis系列-存储篇string主要操作函数小结 3.Redis系列-存储篇list主要操作函数小结 ...
- Picasso 加载图片到RelativeLayout之解决方案
Picasso 加载图片到ImageView 或者自己的自定义View都是可以直接调用对应API的,但是用into(0直接也加载到RelatieLayout就不好使了,可以这样来: Picasso.w ...
- weiphp 微信公众号用程序来设置指定内容消息回复业务逻辑操作
微信公众号机器人回复设置 在公众号插件里面的Robot- Model- weixinAddonModel.php里面的 reply设置 reply($dataArr,$keywordArr) 解析方法 ...
- php cli模式没有加载php.ini
这两天在虚拟机的linux里编译安装了php,同时也把swoole的扩展也编译上了.在/etc/php.ini里加上了extension=swoole.so,但是用php -m 查看加载的模块并没有s ...
- Delphi 取外网IP
近日偶要做个程序,需要获得外网IP,偶去网上找相关资料,发现都不尽如人意,有的只能获得本地网卡的IP,有的通过httpget控件获取IP,还有甚者做个asp再调用偶是个懒人,而且上面提到的方法,不是获 ...
- FastJSON应用前测试
FastJSON 应用前测试 FastJSON是一个很好的java开源json工具类库,相比其他同类的json类库,它的速度的确是fast,最快!但是文档做得不好,在应用前不得不亲测一些功能.\ 实际 ...
- Codeforces 241B
因为博客园的公式编辑有点坑,所以-- 原题
- C++ 之再继续
1C++函数重载,内联函数(for程序性能优化),函数递归
- wxpython 中的所有控件及高级应用
转自http://xoomer.virgilio.it/infinity77/Phoenix/lib.agw.html,,,哈哈终于找到了这块的内容,书上基本没有讲解 This is the Adva ...
- sharepoint 2013 reporting services 远程server返回错误: (500) 内部server错误。
在sharepoint 2013部署reporting services过程中,点击管理中心,server上的服务.系统配置.提示了一个错误: 远程server返回错误: (500) 内部server ...