We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Since head is still pointing to the node it was before the recursive call (which is now at the end of the list), head.next.next= head; head.next=null correctly places head at the end of the list.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse a linked list
You are viewing a single comment's thread. Return to all comments →
Linked list before recursive call:
Linked list after recursive call:
Since head is still pointing to the node it was before the recursive call (which is now at the end of the list), head.next.next= head; head.next=null correctly places head at the end of the list.