[Leetcode] Insertion Sort List (Java)
2014-02-17 12:54
525 查看
Sort a linked list using insertion sort.
链表插入排序
链表插入排序
public class Solution { public ListNode insertionSortList(ListNode head) { ListNode ret = new ListNode(-1); ListNode cur = head; ListNode pre = ret; while(cur!=null){ ListNode tmp = cur; cur=cur.next; if(pre.next==null){ pre.next=tmp; tmp.next=null; pre=ret; }else { while(pre.next!=null&&pre.next.val<tmp.val){ pre=pre.next; } tmp.next=pre.next; pre.next=tmp; pre=ret; } } return ret.next; } }
相关文章推荐
- 【LeetCode-面试算法经典-Java实现】【147-Insertion Sort List(链表插入排序)】
- Insertion Sort List Leetcode java
- leetcode 147 Insertion Sort List java 算法
- [Leetcode][JAVA] Insertion Sort List
- LeetCode 147 — Insertion Sort List(C++ Java Python)
- Insertion Sort List Leetcode java
- LeetCode:Insertion Sort List (Java)
- LeetCode147_Insertion Sort List(用插入排序算法对链表进行排序) Java题解
- Java for LeetCode 147 Insertion Sort List
- LeetCode—Insertion Sort List 解题报告
- leetcode 133: Insertion Sort List
- [LeetCode]Insertion Sort List
- LeetCode | Insertion Sort List
- leetcode - Insertion Sort List
- leetcode做题总结,题目Insertion Sort List 2013/11/12
- LeetCode_Insertion Sort List
- leetCode解题报告之Insertion Sort List
- [LeetCode] Insertion Sort List
- leetCode(4):Insertion Sort List 分类: leetCode 2015-06-17 09:42 205人阅读 评论(0) 收藏
- leetcode解题之148. Sort List Java版(对链表排序)