💻 Day 53 of #100DaysOfCode – LeetCode #206: Reverse Linked List Today’s challenge was one of the most classic problems in data structures — reversing a linked list. This problem is a great way to strengthen your understanding of pointers and linked list manipulation. 🧩 Problem: Given the head of a singly linked list, reverse it and return the new head. ⚙ Approach: I used an iterative approach with three pointers: prev, curr, and next. Store the next node Reverse the current node’s pointer Move forward until the list is reversed 🧠 Key Learning: This problem really helped me visualize how pointers work in linked structures — a great exercise for understanding memory links and iterative logic. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) Here’s my simple Java solution: class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null, curr = head; while (curr != null) { ListNode next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; } } 🔥 Every day, one step closer to mastering data structures! #Day53 #LeetCode #Java #100DaysOfCode #CodingJourney #LinkedList #DSA #Programming #ReverseLinkedList
Reversing a linked list with Java and LeetCode
More Relevant Posts
-
💻 Day 53 of #100DaysOfCode – LeetCode #206: Reverse Linked List Today’s challenge was one of the most classic problems in data structures — reversing a linked list. This problem is a great way to strengthen your understanding of pointers and linked list manipulation. 🧩 Problem: Given the head of a singly linked list, reverse it and return the new head. ⚙ Approach: I used an iterative approach with three pointers: prev, curr, and next. Store the next node Reverse the current node’s pointer Move forward until the list is reversed 🧠 Key Learning: This problem really helped me visualize how pointers work in linked structures — a great exercise for understanding memory links and iterative logic. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) Here’s my simple Java solution: class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null, curr = head; while (curr != null) { ListNode next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; } } 🔥 Every day, one step closer to mastering data structures! #Day53 #LeetCode #Java #100DaysOfCode #CodingJourney #LinkedList #DSA #Programming #ReverseLinkedList
To view or add a comment, sign in
-
-
💻 Day 53 of #100DaysOfCode – LeetCode #206: Reverse Linked List Today’s challenge was one of the most classic problems in data structures — reversing a linked list. This problem is a great way to strengthen your understanding of pointers and linked list manipulation. 🧩 Problem: Given the head of a singly linked list, reverse it and return the new head. ⚙️ Approach: I used an iterative approach with three pointers: prev, curr, and next. Store the next node Reverse the current node’s pointer Move forward until the list is reversed 🧠 Key Learning: This problem really helped me visualize how pointers work in linked structures — a great exercise for understanding memory links and iterative logic. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) Here’s my simple Java solution: class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null, curr = head; while (curr != null) { ListNode next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; } } 🔥 Every day, one step closer to mastering data structures! #Day53 #LeetCode #Java #100DaysOfCode #CodingJourney #LinkedList #DSA #Programming #ReverseLinkedList
To view or add a comment, sign in
-
-
💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
🎯 Day 82 of #100DaysOfCode – LeetCode 137: Single Number II Today’s challenge was about identifying the unique number in an array where every element appears three times except for one. 🧩 Problem Statement: Given an integer array nums, where every element appears exactly three times except for one, find that single element that appears only once. Example: Input: [2,2,3,2] Output: 3 💭 Approach 1: Using HashMap At first, I solved this using a HashMap to count the frequency of each number. Traverse the array and store each element’s occurrence. Return the element whose count equals 1. 🕒 Time Complexity: O(n) 💾 Space Complexity: O(n) 🚀 Key Takeaway: Sometimes, the best way to optimize is not by adding more data structures, but by understanding how data behaves at the bit level. #100DaysOfCode #Day82 #LeetCode #Java #ProblemSolving #DSA #CodingJourney #BitManipulation #KeepLearning
To view or add a comment, sign in
-
-
Sharing the simple script I developed for my PhD research: an interactive Java program that generates problem instance files and matching solution files for vehicle routing / dropoff coordination experiments. It currently: Supports instance templates: 2, 3, 5, 9, 12, 15, 18, 21 Prompts for integer scenario parameters (vehicles, customers, depots, deployment time, capacity, demand/frequency, start/end depot) Produces two files per run: FINALDATA/p{N}.txt and FINALSOLUTION/pr{N}.txt (paths currently hard-coded) Includes ready-made solution routes and objective values per template (useful for benchmarking or as fixtures) #VehicleRouting #VRP #Logistics #RoutingAlgorithms https://lnkd.in/giFPQiNC
To view or add a comment, sign in
-
💼 Day 54 of #100DaysOfCode Challenge 🚀 📘 Problem: LeetCode #217 – Contains Duplicate 🧠 Topic: HashSet | Array | Data Structures 🔍 Problem Statement: Given an integer array nums, return true if any value appears at least twice in the array, and false if every element is distinct. ⚙ Approach: Used a HashSet to check for duplicates efficiently. Traverse through each number in the array. If the number already exists in the set → return true. Otherwise, add it to the set and continue. If loop ends with no duplicates → return false. 💻 Java Solution: import java.util.HashSet; public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> set = new HashSet<>(); for (int num : nums) { if (set.contains(num)) { return true; } set.add(num); } return false; } } ⏱ Complexity Analysis: Time: O(n) Space: O(n) 💬 Takeaway: Simple but powerful — using the right data structure like HashSet can make problems easy and efficient to solve. ⚡ #100DaysOfCode #Day54 #LeetCode #Java #CodingChallenge #DSA #HashSet #ProblemSolving #Programmer #TechJourney
To view or add a comment, sign in
-
-
💼 Day 54 of #100DaysOfCode Challenge 🚀 📘 Problem: LeetCode #217 – Contains Duplicate 🧠 Topic: HashSet | Array | Data Structures 🔍 Problem Statement: Given an integer array nums, return true if any value appears at least twice in the array, and false if every element is distinct. ⚙ Approach: Used a HashSet to check for duplicates efficiently. Traverse through each number in the array. If the number already exists in the set → return true. Otherwise, add it to the set and continue. If loop ends with no duplicates → return false. 💻 Java Solution: import java.util.HashSet; public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> set = new HashSet<>(); for (int num : nums) { if (set.contains(num)) { return true; } set.add(num); } return false; } } ⏱ Complexity Analysis: Time: O(n) Space: O(n) 💬 Takeaway: Simple but powerful — using the right data structure like HashSet can make problems easy and efficient to solve. ⚡ #100DaysOfCode #Day54 #LeetCode #Java #CodingChallenge #DSA #HashSet #ProblemSolving #Programmer #TechJourney
To view or add a comment, sign in
-
-
🚀 Just implemented a custom Vector<T> class in Java — a dynamic array structure that grows automatically as elements are added. It supports key operations like push_back, pop_back, front, back, clear, and more — all while practicing the concepts of generics, dynamic memory allocation, and data encapsulation. Rebuilding core data structures from scratch is a great way to understand how tools like ArrayList work internally. 💻 #Java #DSA #LearningByDoing #CodingJourney #DataStructures Nohit Singh,Shreyash Khedekar,Anshuman Singh,Arpit Jain
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development