给出一个排序的整数数组,删除在位上的重复,使每个元素只出现一次,返回新的长度.不要为另一个组分配额外的空间.例如,如果输入组是 [1,1,2],输出应该是 2,并且该组应该修改为 [1,2].
To remove duplicates in-place from a sorted array, one approach is to use two pointers. We can iterate through the array with one pointer and compare the current element with the previous element. If they are the same, we move the second pointer forward until we find a different element. We can then overwrite the duplicate element with the unique element found by the second pointer. This way, we can eliminate duplicates from the sorted array without using any extra space. Here's the code:

```
def remove_duplicates(nums):
    if not nums:
        return 0
    i = 0
    for j in range(1, len(nums)):
        if nums[j] != nums[i]:
            i += 1
            nums[i] = nums[j]
    return i + 1
```

This function takes an input array and returns the new length of the array after removing duplicates. We initialize the first pointer `i` to 0 and iterate through the array with the second pointer `j`, starting from index 1. If the current element at index `j` is not equal to the previous element at index `i`, we increment `i` and copy the element at index `j` to index `i`. Eventually, all duplicate elements will be removed and `i + 1` will be the new length of the array.