Implement the removeDuplicatesSortedArrayLength method that returns the length after removing duplicates from a sorted array.
The input contains a sorted integer array nums and its length size. Your task is to remove duplicate values logically and return the number of unique values.
Because the array is sorted, duplicate values appear next to each other. The returned length represents how many positions would remain after keeping each value only once.
For example, [1,1,2] contains the unique values 1 and 2, so the answer is 2.
Use a write pointer to track the position where the next unique value should be placed.
Start with the first value as unique. Then scan the array from the second value onward. Whenever the current value is different from the previous value, write it at the current write position and move the write pointer forward.
At the end, the write pointer value is the count of unique elements.
Pseudocode:
function removeDuplicatesSortedArrayLength(nums, size):
if size == 0:
return 0
write = 1
for read from 1 to size - 1:
if nums[read] != nums[read - 1]:
nums[write] = nums[read]
write++
return write