题目描述 在O(n log n)的时间内使用常数级空间复杂度对链表进行排序。 Sort a linked list in O(n log n) time using constant space complexity. /** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode sortList(ListNode head) { if(head == null || head.next == null){ return head; } ListNode start = head; ListNode mid = getMid(head); ListNode end = mid.next; mid.next = null; return merge(sortList(start),sortList(end)); } public ListNode merge(ListNode node1, ListNode node2){ if(node1 == null) { return node2; } if(node2 == null){ return node1; } ListNode min = new ListNode(-1); ListNode cur = min;