148. Sort List
Description
Sort a linked list in O(n log n) time using constant space complexity.
Example 11
2Input: 4->2->1->3
Output: 1->2->3->4
Idea
merge sort, divide and conquer
Code
body
1 | def sortList(self, head): |
find middle: fast and slow pointer
1 | def findMid(self, head): |
merge
1 | def merge(self, head1, head2): |