Java: 1ms solution


  • 0
    L
     public int removeDuplicates(int[] nums) {
        
      
        if(nums.length==0)
        return 0;
        int i,j;
        int temp=nums[0];
        for(i=1,j=1;i<nums.length;)
        {
            if(nums[i]==temp && i<nums.length)
            {
                i++;
                
            }else{
                
                
                temp=nums[i];
                nums[j]=temp;
                j++;i++;
            }
        
            
            
        }
        
        return j;
    }

Log in to reply
 

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