Reverse Linked List in Java

🔥 Day 100 of #100DaysOfCode — FINAL DAY 🎯 Today’s problem: LeetCode – Reverse Linked List 🔗🔄 📌 Problem Summary You are given the head of a singly linked list. 👉 Reverse the list and return the new head. Example: [1,2,3,4,5] → [5,4,3,2,1] 🧠 Approach: Iterative (Two Pointers) We reverse the list by changing the direction of pointers. ⚙️ Logic We maintain three pointers: prev → previous node (initially null) curr → current node (starts at head) next → temporary pointer to store next node 💻 Code Insight ListNode prev = null; ListNode curr = head; while(curr != null){ ListNode temp = curr.next; curr.next = prev; prev = curr; curr = temp; } return prev; 💡 How It Works At each step: Reverse the link (curr.next = prev) Move both pointers forward Gradually, the entire list gets reversed. ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 🚀 Performance Runtime: 0 ms Beats 100% submissions 🔥 Memory: 44.29 MB 🧠 Key Learning This is one of the most fundamental linked list problems. It teaches: Pointer manipulation In-place operations Iterative thinking 🎉 100 Days Completed! From: Arrays & Strings Sliding Window Stack & Queue Monotonic Stack Binary Search Linked Lists 👉 To building strong problem-solving skills 💪 Consistency > Motivation 🔥 🚀 What’s Next? Start Advanced DSA (Graphs / DP) Build real-world projects Contribute to Open Source (GSoC ready 💪) Practice mock interviews 💬 This journey is just the beginning. #100DaysOfCode #LeetCode #DSA #Java #CodingJourney #Consistency #InterviewPrep

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories