p147 发表于 2016-08-05 | 分类于 blog | LeetCode 147 Insertion Sort List 题解1.题目: Sort a linked list using insertion sort. 题意: 用插入排序排序一个链表 2.解题思路: 3.代码 [title] [] [url] [link text]1234567891011121314151617181920212223242526272829 public class Solution { public ListNode insertionSortList(ListNode head) { if (head == null||head.next==null) { return head; } ListNode ans = new ListNode(Integer.MIN_VALUE); ListNode node = head; while (node!=null) { ListNode nextListNode =node.next; ListNode inListNode =ans; while (inListNode.next!=null) { if (inListNode.next.val>node.val) break; inListNode=inListNode.next; } node.next=inListNode.next; inListNode.next=node; node=nextListNode; } return ans.next; }} 4.一些总结: