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的更多相关文章

  1. 【LeetCode】147. Insertion Sort List 解题报告(Python)

    [LeetCode]147. Insertion Sort List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...

  2. LeetCode解题报告:Insertion Sort List

    Insertion Sort List Sort a linked list using insertion sort. leetcode subject思路:标准的插入排序.考察一下链表的操作. 对 ...

  3. LeetCode OJ 147. Insertion Sort List

    Sort a linked list using insertion sort. Subscribe to see which companies asked this question 解答 对于链 ...

  4. 【LeetCode OJ】Insertion Sort List

    Problem: Sort a linked list using insertion sort. The node of the linked list is defined as: /** * D ...

  5. 【leetcode】147. Insertion Sort List

    Sort a linked list using insertion sort. 链表的插入排序. 需要创建一个虚拟节点.注意点就是不要节点之间断了. class Solution { public: ...

  6. LeetCode OJ:Insertion Sort List (插入排序链表)

    Sort a linked list using insertion sort. 用插入排序来排序一个list,额, 我写的好麻烦啊, debug了好久,至少提交了5次...写吐了快,先贴代码,写的也 ...

  7. 【刷题-LeetCode】147 Insertion Sort List

    Insertion Sort List Sort a linked list using insertion sort. A graphical example of insertion sort. ...

  8. Insertion Sort List Leetcode java

    题目: Sort a linked list using insertion sort. 题解: Insertion Sort就是把一个一个元素往已排好序的list中插入的过程. 初始时,sorted ...

  9. [LeetCode 题解]: Insertion Sort List

    Sort a linked list using insertion sort. 题目要求:链表的插入排序,由于没有时间复杂度的要求,可以直接循环操作. /** * Definition for si ...

随机推荐

  1. JAVA微信服务号开发简记

    现在微信公众平台的开发已经越来越普遍,这次开发需要用到微信公众平台.所以这边做一个简单的记录,也算是给那些没踩过坑的童鞋一些启示吧.我将分几块来简单的描述一下,之后会做详细的说明. 基本认证信息说明 ...

  2. 数据绑定到ADO.NET

    // Define a DataSet with a single DataTable. DataSet dsInternal = new DataSet(); dsInternal.Tables.Ad ...

  3. LVS专题-(3) 虚拟ip理解

    1.虚拟IP是什么? 要是单讲解虚拟 IP,理解起来很困难,所以干脆把 动态 IP .固定 IP .实体 IP 与虚拟 IP都讲解一下,加深理解和知识扩展 实体 IP:在网络的世界里,为了要辨识每一部 ...

  4. java 操作 RabbitMQ 发送、接受消息

    例子1 Producer.java import java.io.IOException; import java.util.concurrent.TimeoutException; import c ...

  5. Spring <context:component-scan>标签属性 use-default-filters 以及子标签 include-filter使用说明

    Spring <context:component-scan>标签作用有很多,最基本就是 开启包扫描,可以使用@Component.@Service.@Component等注解: 今天要作 ...

  6. Docker镜像的获取和推送

    查找镜像 查找镜像的方法有主要有两种,一种是在Docker Hub官方网站查找,网址为https://hub.docker.com/ 另一种方法是在命令行界面中通过docker serach < ...

  7. jQuery找到GridView控件ItemTemplate模版内的控件

    可以使用下面的方法,jQuery找到GridView控件ItemTemplate模版内的CheckBox: 使用jQuery的find()方法:

  8. JavaSE Set集合

    明确Set集合接口的特点. java.util.Set接口和java.util.List接口一样,同样继承自Collection接口,它与Collection接口中的方法基本一致,并没有对Collec ...

  9. 【Redis】1、Jedis对管道、事务以及Watch的操作来应对高并发

    对于一个互联网平台来说,高并发是经常会遇到的场景.最有代表性的比如秒杀和抢购.高并发会出现三个特点: 1.高并发读取 2.高并发写入(一致性) 3.出现超卖问题 前端如何应对? 1.缓存静态数据,例如 ...

  10. JAVA项目工具包集合

    本文包括工具的下载以及配置,持续更新中…… 1 JDK 官网:https://www.oracle.com 下载:https://www.oracle.com/technetwork/java/jav ...