Simple java solution


  • 0
    N
    public int removeDuplicates(int[] nums) {
        if (nums.length <= 2)
            return nums.length;
        int i = 0;
        int count = 0;
        while (i < nums.length - 2 - count)
        {
            if (nums[i] == nums[i + 2 + count])
                count++;
            else {
                nums[i + 2] = nums[i + 2 + count];
                i++;
            }
        }
        return nums.length - count;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.