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
|
912 Discussions
|
Please Login in order to post a comment
My python solution :
My Java solution:
My Java solution with o(n) time complexity and o(1) space complexity:
public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) { if(llist == null) return null; if(llist.next == null) return llist;
if(llist == null) return null; if(llist.next == null) return llist;
My Java solution with o(n) time complexity and o(1) space complexity: