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.
In python you can switch variables in a single line like shown above, so the code goes through each node at a time reversing the connections until you hit the final node.
The last node returned would be the final one encountered, which is now the first element.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse a doubly linked list
You are viewing a single comment's thread. Return to all comments →
I like this solution, simple and elegant.
In python you can switch variables in a single line like shown above, so the code goes through each node at a time reversing the connections until you hit the final node.
The last node returned would be the final one encountered, which is now the first element.