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.
publicstaticDoublyLinkedListNodereverse(DoublyLinkedListNodellist){DoublyLinkedListNodecurrent=llist;DoublyLinkedListNodeprev=null;while(current!=null){DoublyLinkedListNodenextNode=current.next;current.next=prev;current.prev=nextNode;// swap prev and next pointersprev=current;current=nextNode;}//prev points to the new head of the reversed listreturnprev;}
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 →
Java 15 O(n)