https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
双指针
public static int removeDuplicates(int[] nums) {
int n = nums.length;
if (n == 0)
return 0;
//定义两个指针fast和slow 分别为快指针和慢指针,快指针表示遍历数组到达的下标位置,慢指针表示下一个不同元素要填入的下标位置,
int fast = 1, slow = 1;
while (fast < n) {
if (nums[fast] != nums[fast - 1]) {
nums[slow] = nums[fast];
slow++;
}
fast++;
}
return slow;
}