[LeetCode]147 Insertion Sort List
2015-01-08 18:29
405 查看
https://oj.leetcode.com/problems/insertion-sort-list/
http://blog.csdn.net/linhuanmars/article/details/21144553
http://blog.csdn.net/linhuanmars/article/details/21144553
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode insertionSortList(ListNode head) { if (head == null || head.next == null) return head; // Add dummy head ListNode dummyhead = new ListNode(0); ListNode pre; ListNode cur = head; while(cur!=null) { ListNode next = cur.next; pre = dummyhead; while(pre.next!=null && pre.next.val<=cur.val) pre = pre.next; cur.next = pre.next; pre.next = cur; cur = next; } return dummyhead.next; } }
相关文章推荐
- LeetCode 147 Insertion Sort List
- LeetCode 147 Insertion Sort List(链表插入排序)
- leetcode[147]Insertion Sort List
- [Leetcode] #147 Insertion Sort List
- LeetCode 147 Insertion Sort List
- leetcode-147 Insertion Sort List
- (Leetcode 147)Insertion Sort List
- [leetcode147]insertion sort list
- [Leetcode]#147 Insertion Sort List
- LeetCode(147) Insertion Sort List
- LeetCode147: Insertion Sort List
- LeetCode 147 — Insertion Sort List(C++ Java Python)
- leetcode-Insertion Sort List-147
- Leetcode 147 Insertion Sort List
- Java for LeetCode 147 Insertion Sort List
- LeetCode 147:Insertion Sort List
- leetcode 147 Insertion Sort List java 算法
- 【LEETCODE】147- Insertion Sort List [Python]
- leetcode[147]:Insertion Sort List
- LeetCode 147 Insertion Sort List(链表)