26_Remove Duplicates from Sorted Array
Last updated
Was this helpful?
Last updated
Was this helpful?
Given a sorted array, remove the duplicates 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 with O(1) extra memory.
Example:
If we really want to delete those duplicated elements:
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.
Leetcode 27
Leetcode 80
Time complexity:
Space complexity: