Given the head of a singly linked list, reverse the list, and return the reversed list.
Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?
- iterative solution
- Time : O(n)
- Space : O(1)
c++
1 | /** |
- recursive solution
- Time : O(n)
- Space : O(1)
c++
1 | /** |