Problem
Sort a linked list in O(n log n) time using constant space complexity.
Examples
1 | put: 4->2->1->3 |
1 | Input: -1->5->3->4->0 |
Solution1
Method: Divide and Conquer
Time Complexity: O(n log n)
Space Complexity: O(1)
1 | # Definition for singly-linked list. |
Solution2
Method: Divide and Conquer without recursive
Time Complexity: O(n log n)
Space Complexity: O(1)
1 | class Solution(object): |