LinkedList-147-Insertion Sort List
2018-02-01 21:14
288 查看
Description:
Sort a linked list using insertion sort.
Solution:
Sort a linked list using insertion sort.
Solution:
class Solution { public ListNode insertionSortList(ListNode head) { if(head == null) return null; ListNode cur = head; ListNode result = new ListNode(0); ListNode helper = result; ListNode next = null; while(cur != null){ next = cur.next; if(helper.next == null || helper.next.val > cur.val) helper = result; while(helper.next != null && helper.next.val <cur.val) helper = helper.next; cur.next = helper.next; helper.next = cur; cur = next; } return result.next; } }
相关文章推荐
- leetcode-Insertion Sort List-147
- leetcode上的Sort a linked list using insertion sort
- [LeedCode OJ]#147 Insertion Sort List
- LeetCode 147 — Insertion Sort List(C++ Java Python)
- leetcode[147]Insertion Sort List
- leetcode_147 Insertion Sort List
- The Solution to LeetCode 147 Insertion Sort List
- LeetCode 147:Insertion Sort List
- [leetcode 147] Insertion Sort List
- Java for LeetCode 147 Insertion Sort List
- leetcode 147 —— Insertion Sort List
- leetCode #147 Insertion Sort List
- LeetCode: Insertion Sort List [147]
- leetcode_c++:链表:Insertion Sort List(147)
- LeetCode 147 Insertion Sort List
- LeetCode147—Insertion Sort List
- LeetCode(147) Insertion Sort List
- 147 Insertion Sort List
- Leetcode 147 Insertion Sort List
- [leedcode 147] Insertion Sort List