26_Remove Duplicates from Sorted Array
28. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
Example:
Solution 1
If we really want to delete those duplicated elements:
Solution 2
If we can just put those non-duplicated elements at the begining of the array:
Need two pointers. Use fast pointer to loop from left to right. Use slow pointer to record the first place that have duplicates.
Variant
Leetcode 27
Leetcode 80
Last updated