26. Remove Duplicates from Sorted Array
Intitution
In a sorted array, duplicates are always next to each other. So use a slow and fast pointer where the slow only moves when an unique element is encountered. Just scan through the array, and whenever we see a new (unique) element, overwrite the front part of the array with it, maintaining only the distinct values in-place.
Complexity
Space Complexity
Time Complexity
Code
Last updated