package LinkedList
// 时间复杂度: O(n * log n), 空间复杂度: O(log n)
func sortList(head *ListNode) *ListNode {
if head == nil || head.Next == nil {
return head
}
slow, fast := head, head
for fast.Next != nil && fast.Next.Next != nil {
slow = slow.Next
fast = fast.Next.Next
}
fast = slow.Next
slow.Next = nil
head1 := sortList(head)
head2 := sortList(fast)
newHead := mergeTwoLists(head1, head2)
return newHead
}