Removing Duplicates from Sorted Array in Java

📌 Day 3/100 - Remove Duplicates from Sorted Array (LeetCode 26) 🔹 Problem: Given a sorted array, remove the duplicates in-place so that each element appears only once and return the new length. You must modify the array without using extra space for another array. 🔹 Approach: I used a simple counting-based approach: Iterate through the array using a single loop. If the current element is the same as the next, skip it. Otherwise, place it at the current count index and increment count. Finally, return count as the number of unique elements. 🔹 Key Learning: Practiced in-place array modification efficiently without extra space. Improved understanding of loop-based filtering logic. Realized that sometimes the simplest linear approach works best! Consistency compounds — each problem adds a new layer of confidence! 🚀#100DaysOfCode #LeetCode #Java #ProblemSolving #Array #DSA #TwoPointers

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories