Insertion Sort List
2014-02-24 04:53
295 查看
public class Solution { public ListNode insertionSortList(ListNode head) { if(head==null) return head; ListNode safe = new ListNode(Integer.MIN_VALUE); ListNode p2 = head; while(p2!=null){ ListNode pre = find(safe,p2); ListNode next = p2.next; p2.next = pre.next; pre.next = p2; p2 = next; } return safe.next; } public ListNode find(ListNode p1,ListNode p2){ ListNode cur = p1, pre = null; while(cur!=null && cur.val<=p2.val){ pre = cur; cur = cur.next; } return pre; } }
View Code
Sort a linked list using insertion sort
相关文章推荐
- Insertion Sort List
- [leetcode] Insertion Sort List(python)
- leetcode——Insertion Sort List 对链表进行插入排序(AC)
- leetcode---insertion-sort-list---链表
- LeetCode | Insertion Sort List
- LeetCode -- Insertion Sort List
- [LeetCode 题解]: Insertion Sort List
- [leetcode] Insertion Sort List
- (Leetcode 147)Insertion Sort List
- LeetCode(147) Insertion Sort List
- LeetCode:Insertion Sort List//链表插入排序
- LeetCode147—Insertion Sort List
- [LeetCode 148] Insertion Sort List
- LeetCode-Insertion Sort List[AC源码]
- Leetcode:Insertion Sort List
- 【Leetcode】Insertion Sort List
- [leetcode]Insertion Sort List
- Insertion Sort List
- leetcode-147 Insertion Sort List
- 【LeetCode】-Insertion Sort List