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 change the array nums such that the first k elements of nums hold the unique elements in the order they were present initially.
Example 1
Input: nums = [0,0,1,1,1,2,2,3,3,4]
Output: [0,1,2,3,4]
Explanation: Keeping one copy of each value in order gives [0,1,2,3,4], so k = 5.
Example 2
Input: nums = [1,1,2]
Output: [1,2]
Explanation: The second 1 is dropped, leaving [1,2].
Example 3
Input: nums = [1]
Output: [1]
Explanation: A single element has no duplicates.
Because the array is sorted, duplicates are adjacent. Keep a slow write-pointer at the last unique value; advance a fast pointer, and whenever it finds a value different from the last kept one, write it forward.
Run checks all cases above. Submit evaluates all test cases.