Easy to understand java solution 2ms


  • 0
    N
    public int removeDuplicates(int[] nums) {
        if(nums.length==0) return 0;
        int n=0;
        for(int i=0;i<nums.length-1;i++)
        {
          
            if(nums[i]!=nums[i+1]) {
                nums[++n]=nums[i+1];
            }
            
            
        }
    
        return (n+1);
        
    }

Log in to reply
 

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