You are viewing a single comment's thread. Return to all comments →
Simple java solution TC-O(N) SC-O(1)
public static DoublyLinkedListNode reverse(DoublyLinkedListNode llist) { if(llist == null || llist.next == null){ return llist; } DoublyLinkedListNode last = null; DoublyLinkedListNode curr = llist; while(curr!=null){ last = curr.prev; curr.prev = curr.next; curr.next = last; curr = curr.prev; } return last.prev; } }
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 →
Simple java solution TC-O(N) SC-O(1)