Easy · Arrays

Remove duplicates in place

Given an integer array nums sorted in non-decreasing order, remove the duplicates in place so the first k slots hold each distinct value exactly once, in their original order, and return k (whatever is left after slot k does not matter).

Examples

Example 1

[1,1,2,2,3]

Output: length 3

Example 2

[0,0,1,1,1,2,3]

Output: length 4

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Arrays problems