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
|
913 Discussions
|
Please Login in order to post a comment
Great approach! Reversing a singly linked list by inserting nodes at the beginning of a new list is efficient and clean. This function is especially useful in coding interviews and beginner data structure practice.
Also, if anyone is looking for a peaceful break from coding or wants to learn to read the Quran online, I invite you to visit my website: 👉 Zeenat ul Quran – Online Quran Learning Platform
It’s a great resource for all ages to learn Quran, namaz, and Islamic basics from home. 😊
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;