Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.
Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:
- Change the array
numssuch that the firstkelements ofnumscontain the unique elements in the order they were present innumsinitially. - Return
k.
Example:
- Input:
nums = [1,1,2] - Output:
2, nums = [1,2,_]
0
0
l
r
0
1
1
2
1
3
1
4
2
5
2
6
3
7
3
8
4
9
Step 1 / 11
Step 1:
Initialize l=1 (where next unique goes). Start r loop from 1.
Pointers: l=1, r=1
Focus: default @ [1]