Reverse Linked List
Reverse a singly linked list.
Example:
Follow up:
A linked list can be reversed either iteratively or recursively. Could you implement both?
(Iterative)
Time complexity : O(n). Assume that n is the list's length, the time complexity is O(n)
Space complexity : O(1).
(Recursive)
Time complexity : O(n). Assume that is the list's length, the time complexity is O(n).
Space complexity : O(n). The extra space comes from implicit stack space due to recursion. The recursion could go up to n levels deep.
Last updated