Problem
Reverse a singly linked list.
Example
1 | Input: 1->2->3->4->5->NULL |
Solution1
Method: Iterative
Time Complexity: O(n)
Space Complexity: O(1)
1 | # Definition for singly-linked list. |
or
1 | # Definition for singly-linked list. |
Solution2
Method: Recursive
Time Complexity:
Space Complexity:
1 | # Definition for singly-linked list. |
or
1 | # Definition for singly-linked list. |