Reverse a singly linked list.
- Difficulty: EASY
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
A linked list can be reversed either iteratively or recursively. Could you implement both?
- Use iteraitve way to add the node in front of the reversed list
- Time complexity:
- Space complexity:
- Time complexity:
- Use recursive way to reverse each node in the linked list
- Time complexity:
- Space complexity:
- Time complexity: