The array nums holds integers in non-decreasing order. Remove the repeated values in place so that each value appears only once. Keep the values in the same order. Return the number of different values.
Say the array has k different values. To pass, you must do two things:
- Change
nums so that its first k places hold the different values, in their original order. What is stored after the first k places does not matter.
- Return
k.
How this judge checks it. It reads two things after your function ends: the number k that you return, and the first k places of nums. Places after the first k are not checked. In the test results the answer is written as [k, [the first k places of nums]]. For example 1 it is [3,[2,5,7]].
Examples
Example 1:
Input: nums = [2,2,5,5,5,7]
Output: 3, nums = [2,5,7,_,_,_]
Explanation: There are 3 different values: 2, 5 and 7. They fill the first 3 places. The underscores mean "any value".
Example 2:
Input: nums = [1,2,3]
Output: 3, nums = [1,2,3]
Explanation: All values are already different.
Example 3:
Input: nums = [4,4,4,4]
Output: 1, nums = [4,_,_,_]
Explanation: Only one different value.