leetcode Insertion Sort List
2016-05-31 12:32
302 查看
题目链接
/** * 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 head; } ListNode result=head; ListNode current=head.next; head.next=null; while(current!=null) { ListNode temp=current.next; if(result.val>current.val) { current.next=result; result=current; current=temp; continue; } ListNode pointer=result; while(pointer.next!=null&¤t.val>pointer.next.val) { pointer=pointer.next; } if(pointer.next==null) { pointer.next=current; current.next=null; } else { current.next=pointer.next; pointer.next=current; } current=temp; } return result; } }
相关文章推荐
- spark环境搭建及简单程序使用
- php数组
- 关于Linux平台下的ZFS文件系统最新情况说明
- Ubuntu server 11.04安装memcache及php使用memcache来存储session的方法
- QT 打开 保存 文件对话框
- JS学习第一课
- 实验中心服务器配置记录
- 巧用vim+sed整理shell脚本文件
- Android手绘效果实现
- NYOJ 448 寻找最大数
- handshake_failure
- 如何利用新浪微博开放平台API获取新浪微博用户数据
- 移动开发|绘制饼图、柱状图、2d、3d统计图表
- HDU 1540 Tunnel Warfare xds
- PHP字符串——编码与转义
- MVVM With ReactiveCocoa让移动开发更简单
- 折腾Python中的Tkinter
- MVVM With ReactiveCocoa让移动开发更简单
- 折腾Python中的Tkinter
- 一个上好的C# http/https类