1ms Java solution O(N) time O(1) space


  • 7
    J
    public int removeDuplicates(int[] nums) 
    {
        if (nums.length<2)
            return nums.length;
                
        int swapped = 1;
        
        for (int i=1; i<nums.length;i++)
            if(nums[i-1]<nums[i])
            {
                nums[swapped] = nums[i];
                swapped++;
            }
        
        return swapped;
    }

Log in to reply
 

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