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.
I like this, the if not head is only for checking if the list is empty. and if not head.prev is the terminate condition for recursive, am I right?
Hi, yes, you are correct on both counts.