emm 题目要求在原地删除,即覆盖掉原有的值。原题链接:https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solution/shan-chu-pai-xu-shu-zu-zhong-de-zhong-fu-tudo/

典型双指针 一快一慢 结合官方的图片更容易看懂。

class Solution {
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if(n==0) {
            return 0;
        }
        int fast=1,slow=1;
        while (fast<n){
            if(nums[fast]!=nums[fast-1]){
                nums[slow]=nums[fast];
                ++slow; //slow 当fast找到新值了再前进
            }
            ++fast; //fast每次都前进
        }
        return slow;
    }
}