原题

别人的思路 非常简洁


function ListNode(val) {
this.val = val;
this.next = null;
} /**
* @param {ListNode} head
* @return {ListNode}
*/
var insertionSortList = function(head) {
if (head === null) {
return head;
}
var helper = new ListNode(0);
var cur = head.next;
var pre = helper;
var next = null;
while (cur != null) {
next = cur.next;
while (pre.next != null && pre.next.val < cur.val) {
pre = pre.next;
}
cur.next = pre.next;
pre.next = cur;
pre = helper;
cur = next;
}
return helper.next;
};

[leetcode] 147. Insertion Sort List (Medium)的更多相关文章

  1. [LeetCode] 147. Insertion Sort List 链表插入排序

    Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...

  2. Java for LeetCode 147 Insertion Sort List

    Sort a linked list using insertion sort. 解题思路: 插入排序,JAVA实现如下: public ListNode insertionSortList(List ...

  3. leetcode 147. Insertion Sort List ----- java

    Sort a linked list using insertion sort. 插入排序. /** * Definition for singly-linked list. * public cla ...

  4. [LeetCode] 147. Insertion Sort List 解题思路

    Sort a linked list using insertion sort. 问题:实现单向链表的插入排序. 这是比较常规的一个算法题目. 从左往右扫列表,每次将指针的下一个元素插入前面已排好序的 ...

  5. LeetCode 147. Insertion Sort List 链表插入排序 C++/Java

    Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...

  6. Leetcode#147 Insertion Sort List

    原题地址 心得:有关链表的题目,多用中间变量,代码写得清晰一点,适当注释 代码: ListNode *insertionSortList(ListNode *head) { if (!head) re ...

  7. [LeetCode]147. Insertion Sort List链表排序

    插入排序的基本思想 把排好的放在一个新的变量中,每次拿出新的,排进去 这个新的变量要有超前节点,因为第一个节点可能会有变动 public ListNode insertionSortList(List ...

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

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

  9. LeetCode OJ 147. Insertion Sort List

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

随机推荐

  1. CDC-更改数据捕获存储过程 (Transact-SQL)-学习

    背景: 在SQLServer2008之前,对数据变更的捕获通常使用触发器.时间戳等低效高成本的功能来实现,所以很多系统都没有做数据变更或者仅仅对核心表做监控. 适用环境: 仅在SQLServer200 ...

  2. 基于python实现的三方组件----Celery

    一.基于python实现的三方组件----Celery 1.作用 用于异步周期任务的处理 2.Celery的组成 (1)任务 app (2)记录任务的缓存(通常用redis或rabbitMQ) 任务记 ...

  3. 【需要重新整理】【mongoDB】mongoDB初见笔记

    A安装(windows版): 1.官网下载安装文件 2.解压 3.配置环境变量 4.win+r cmd>打开控制台配置仓库路径 5.mongod --dbpath=d:/bigMongo//启动 ...

  4. 模拟实现 Tomcat 的核心模块:NIO,HTTP,容器和集群

    如果你想看 Tomcat 源码但又无从入手,不妨从这个项目开始,代码量不多,但包含了 Tomcat 的核心处理流程,并且源码中有相当丰富的注释.相信通过此项目你能了解: NIO 基本编程.HTTP 协 ...

  5. Windows鼠标右键菜单添加SublimeText打开选项

    Windows上将使用SublimeText打开文件的选项添加到鼠标右键菜单. 新建reg后缀的注册表文件,编辑添加内容 Windows Registry Editor Version 5.00 [H ...

  6. resolv.conf 的超时(timeout)与重试(attempts)机制

    /etc/resolv.conf 有两个默认的值至关重要,一个是超时的 timeout,一个是重试的 attempts,默认情况下,前者是 5s 后者是 2 次.这个估计很多工程师都不是很在意,一般情 ...

  7. idea 提示:ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path java.io.IOException解决方法

    Windows系统中的IDEA链接Linux里面的Hadoop的api时出现的问题 提示:ERROR util.Shell: Failed to locate the winutils binary ...

  8. 5.秋招复习简单整理之请介绍一下List和ArrayList的区别,arrayList和HashSet区别?

    第一问:List是接口,ArrayList是List的实现类. 第二问:ArrayList是List的实现类,HashSet是Set的实现类,List和Set都实现了Collection接口. Arr ...

  9. 探究Hybrid-APP技术原理

    探究Hybrid-APP技术原理 author: @TiffanysBear 背景 随着Web技术的发展和移动互联网的发展,Hybrid技术已经成为一种前端开发的主流技术方案.那什么是Hybrid A ...

  10. Elasticsearch(一)开启外网访问

    1. 设置Elasticsearch对外访问的Host 修改Elasticsearch配置文件 elasticsearch.yml : network.host: 128.24.108.84  //在 ...