Reverse a singly linked list
Problem description :
Write a function to reverse a singly linked list.
Input : A linked list
Output : A linked list
- Iterate through linked list with three-pointers
- While iterating at each step reverse the current link’s direction.
Time Complexity :
- O(n) ; where n is the number of nodes in the linked list
This post is a pre-requisite for Given a singly linked list find if it is palindrome. I recommend reading this first, before going to the palindrome post.