代码:
package com.niuke.p5; public class Solution { public ListNode insertionSortList(ListNode head) { ListNode dumpy = new ListNode(Integer.MIN_VALUE); ListNode cur = head; ListNode pre = dumpy; while(cur != null) { ListNode next = cur.next; pre = dumpy; while(pre.next != null && pre.next.val < cur.val) { pre = pre.next; } cur.next = pre.next; pre.next = cur; cur = next; } return dumpy.next; } }