[leetcode] 26. 删除排序数组中的重复项

26. 删除排序数组中的重复项

一开始各种坐标变换把我绕晕了- -,恶心的水题

class Solution {
    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) return 0;
        int j = 0;
        for (int i = 0; i < nums.length; i++)
            if (nums[i] != nums[j]) nums[++j] = nums[i];
        return ++j;
    }
}

猜你喜欢

转载自www.cnblogs.com/acbingo/p/9256510.html