Remove Duplicates From a Sorted Array
Problem Remove duplicates in place from a sorted array and return the new length, then discuss the unsorted-array variant.
Input / Output
- Input: a sorted integer array
nums. - Output: the new length
k; the firstkelements hold the distinct values in order.
Constraints
- 0 ≤ n ≤ 3 × 10^4.
- In place (O(1) extra space) for the sorted case.
Example
[1,1,2,3,3]→[1,2,3], length 3
added …