We’re preparing your current view and syncing the latest data.
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 length of the array after removing duplicates as the returned value. You must do this by modifying the input array in-place with O(1) extra memory.
An integer array nums sorted in non-decreasing order.
Return an integer representing the length of the array after duplicates have been removed. The first part of the array nums should hold the unique elements in order.
0 <= nums.length <= 3 * 10^4 -10^4 <= nums[i] <= 10^4 nums is sorted in non-decreasing order.
Example 1
Input
[1,1,2]
Output
2
Explanation
The array after removing duplicates is [1,2,_]. The length is 2.
Example 2
Input
[0,0,1,1,1,2,2,3,3,4]
Output
5
Explanation
The array after removing duplicates becomes [0,1,2,3,4,,,,,_].