My 1ms small Java Solution


  • 1
    C
    public int removeDuplicates(int[] nums) {
        
        if(nums.length<3)
            return nums.length;
            int count=2;
        for(int i=2; i<nums.length;i++){
            nums[count]=nums[i];
            if(!(nums[count]==nums[count-1] &&  nums[count]==nums[count-2]))
                count++;
        }
        return count;
    }

Log in to reply
 

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