Sort a linked list using insertion sort.

插入排序。

/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode insertionSortList(ListNode head) { if( head == null )
return null; ListNode node = head.next;
head.next = null;
ListNode start = head; while( no sdf sd sdfnull ){
ListNode nn = node.next;
ListNode first = start;
if( node.val < first.val){
node.next = first;
start = node;
}else{
while( first.next != null && first.next.val < node.val )
first = first.next;
node.next = first.next;
first.next = node; } node = nn; }
return start; }
}

leetcode 147. Insertion Sort List ----- java的更多相关文章

  1. Java for LeetCode 147 Insertion Sort List

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

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

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

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

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

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

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

  5. Leetcode#147 Insertion Sort List

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

  6. [leetcode] 147. Insertion Sort List (Medium)

    原题 别人的思路 非常简洁 function ListNode(val) { this.val = val; this.next = null; } /** * @param {ListNode} h ...

  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. 标签navtab

    创建navtab 创建一个navtab有以下两种方式: 1.Data属性:DOM添加属性data-toggle="navtab"后,单击触发. a链接示例: <a href= ...

  2. Thread IsBcakgroud

    C#中,Thread类有一个IsBackground 的属性.MSDN上对它的解释是:获取或设置一个值,该值指示某个线程是否为后台线程.个人感觉这样的解释等于没有解释. .Net中的线程,可以分为后台 ...

  3. Apache虚拟主机(三)

    一.启用 httpd-vhosts.conf 在httpd.conf文件中启用 在文件中搜索:Virtual hosts #Virtual hosts虚拟主机 Include conf/extra/h ...

  4. 2013年7月份第2周51Aspx源码发布详情

    FineOffice自动化办公(OA)源码  2013-7-12 [ VS2010 ]源码描述:此源码使用fineui开发,作为村居使用的系统,所以命名为fineoffice,其实你在此基础上扩成CR ...

  5. JS中关于 一个关于计时器功能效果的实现

    optionSearch(); function optionSearch() { //定义一个清除计时器的变量 var timer = null; //自选标题区域 $("#optiona ...

  6. android application plugins framework

    android插件式开发 android application plugins framework http://code.google.com/p/android-application-plug ...

  7. C++实现python标准库中的Counter

    看python standard library by exmple里面提到一个Counter容器,它像muliset一样,能够维持一个集合,并在常量时间插入元素.查询某个元素的个数,而且还提供了一个 ...

  8. php大力力 [016节] 兄弟连高洛峰php教程(2014年 14章数据库章节列表)

    2015-08-25 php大力力016 兄弟连高洛峰php教程(2014年 14章数据库章节列表) [2014]兄弟连高洛峰 PHP教程14.1.1 复习数据库  15:58 [2014]兄弟连高洛 ...

  9. yii2归档安装

    1.http://www.yiiframework.com/download/ 下载文件 2.如果inint.bat文件一闪而过,没有提示是开发还是生产环境 用编辑器(phpstorm)打开文件在对应 ...

  10. simple grammer

    <?phpecho strlen("Hello world!"); // outputs 12?> <?phpecho str_word_count(" ...