Remove Duplicates from Sorted Array
Keep one copy of each value in a sorted array, in place, by comparing with the last value you kept.
01The problem
nums is sorted in non-decreasing order. Remove the duplicates in place so each value appears once, and return k, the number of unique values. The first k slots must hold them in order.
| Input | Output | First k slots |
|---|---|---|
[1, 1, 2] | 2 | [1, 2] |
[0,0,1,1,1,2,2,3,3,4] | 5 | [0, 1, 2, 3, 4] |
Loading the rest of the lesson…