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.
Reverse a linked list
Reverse a linked list
Sort by
recency
|
909 Discussions
|
Please Login in order to post a comment
if(llist == null) return null; if(llist.next == null) return llist;
My Java solution with o(n) time complexity and o(1) space complexity:
Here is my c++ solution, you can watch video explanation here : https://youtu.be/F4nGusqPIu0
My short and efficient recursive C++ solution:
public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) { if (llist == null || llist.next == null) { return llist; }