You are viewing a single comment's thread. Return to all comments →
I guess you were getting a error because you were not setting the prev pointer to null if the head.next == null..
For example, try this (passes all test cases):
Node Reverse(Node head) { if (head == null) { return head; } if (head.next == null) { head.prev = null; return head; } Node newHead = Reverse(head.next); head.next.next = head; head.prev = head.next; head.next = null; return newHead; }
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 guess you were getting a error because you were not setting the prev pointer to null if the head.next == null..
For example, try this (passes all test cases):