LeetCode题解之Insertion Sort List
1、题目描述

2、题目分析
利用插入排序的算法即可。注意操作指针。
3、代码
ListNode* insertionSortList(ListNode* head) {
if (head == NULL || head->next == NULL)
return head;
ListNode *dummy = new ListNode();
dummy->next = head;
ListNode *pre = dummy;
ListNode *p = head;
ListNode *pn = head->next;
while (pn != NULL) {
pre = dummy;
p = dummy->next;
while (p->val < pn->val) {
p = p->next;
pre = pre->next;
}
ListNode *tmp = pn->next;
pre->next = pn;
pn->next = p;
while (p->next != pn)
p = p->next;
p->next = tmp;
pn = tmp;
}
return dummy->next;
}
LeetCode题解之Insertion Sort List的更多相关文章
- 【LeetCode】147. Insertion Sort List 解题报告(Python)
[LeetCode]147. Insertion Sort List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...
- LeetCode解题报告:Insertion Sort List
Insertion Sort List Sort a linked list using insertion sort. leetcode subject思路:标准的插入排序.考察一下链表的操作. 对 ...
- LeetCode OJ 147. Insertion Sort List
Sort a linked list using insertion sort. Subscribe to see which companies asked this question 解答 对于链 ...
- 【LeetCode OJ】Insertion Sort List
Problem: Sort a linked list using insertion sort. The node of the linked list is defined as: /** * D ...
- 【leetcode】147. Insertion Sort List
Sort a linked list using insertion sort. 链表的插入排序. 需要创建一个虚拟节点.注意点就是不要节点之间断了. class Solution { public: ...
- LeetCode OJ:Insertion Sort List (插入排序链表)
Sort a linked list using insertion sort. 用插入排序来排序一个list,额, 我写的好麻烦啊, debug了好久,至少提交了5次...写吐了快,先贴代码,写的也 ...
- 【刷题-LeetCode】147 Insertion Sort List
Insertion Sort List Sort a linked list using insertion sort. A graphical example of insertion sort. ...
- Insertion Sort List Leetcode java
题目: Sort a linked list using insertion sort. 题解: Insertion Sort就是把一个一个元素往已排好序的list中插入的过程. 初始时,sorted ...
- [LeetCode 题解]: Insertion Sort List
Sort a linked list using insertion sort. 题目要求:链表的插入排序,由于没有时间复杂度的要求,可以直接循环操作. /** * Definition for si ...
随机推荐
- Vue中使用watch来监听数据变化
写法一: methods:{ //监听isMD upProp(){ if(this.isMD){//如果isMD等于true 就把storeManagerName赋值给isStoreManagerNa ...
- JAVA中 XML与数据库互转 学习笔记三
要求 必备知识 JAVA基础知识,XML基础知识,数据库的基本操作. 开发环境 MyEclipse10/MySql5.5 资料下载 源码下载 数据库在数据查询,修改,保存,安全等方面与其他数据处理 ...
- scala-03-list操作
列表 Scala 列表类似于数组,它们所有元素的类型都相同,但是它们也有所不同:列表是不可变的,值一旦被定义了就不能改变,其次列表 具有递归的结构(也就是链接表结构)而数组不是.. 1, 创建 lis ...
- offsetTop、offsetLeft、offsetWidth、offsetHeight的用法
假设 obj 为某个 HTML 控件. obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算上侧位置,整型,单位像素. obj.offsetLeft ...
- Zend Studio下的PHP代码调试
问题:Zend Studio无法调试php代码 安装Zend Debugger 下载 到http://downloads.zend.com/pdt/server-debugger下载最新的debugg ...
- Python模板库Mako的用法
官网地址:http://www.makotemplates.org/ 文档地址:http://docs.makotemplates.org/ 中文文档基本用法地址:http://www.open-op ...
- ActiveMQ专题2: 持久化
AMQ的持久化问题 前言 前面一篇AMQ专题中,我们发现对于Topic这种类型的消息,即使将deliveryMode设置为持久化,只要生产者在消费者之前启动.消息生产者发布的消息还是会丢失.这是符 ...
- maven官方教程
What is Maven? At first glance Maven can appear to be many things, but in a nutshell Maven is an att ...
- webpack4使用mode优化开发环境配置
@subject: webpack mode @author: leinov @date: 2018-11-29 mode webpack的 mode 配置用于提供模式配置选项告诉webpack相应地 ...
- _ViewStart文件应用
在这篇<MVC母版页_Layout.cshtml>http://www.cnblogs.com/insus/p/3380419.html中,把一些已经存在的视图或是新产生的视图加入母版中. ...