You are given a sorted integer array nums, where equal values may appear consecutively. Modify it in place so that every distinct value occurs exactly once, then return the resulting count k.
Your implementation must satisfy all of the following:
O(1) additional memory.nums array.k is returned, positions 0 through k - 1 in nums must hold the distinct values, preserving their original order.nums.k, which is the array length after duplicate values are removed.0 <= len(nums) <= 3 * 10^4-10^4 <= nums[i] <= 10^4nums is ordered non-decreasinglyInput:
-2 -2 5
Output:
2
Explanation: The first 2 positions are updated to [-2, 5].
nums = [-2, -2, 5]2
The input array is [-2, -2, 5].
Input:
-3 -3 -1 0 0 4 4
Output:
4
Explanation: The first 4 positions become [-3, -1, 0, 4].
Input: 7 7 9
Output: 2
nums = [-2, -2, 5]2
The input array is [-2, -2, 5].