Share my simple java solution


  • 0
    J
        public int removeDuplicates(int[] nums) {
        if(nums==null || nums.length<2) return nums.length;
        int i=0;
        int j=1;
        for(j=1; j<nums.length; j++){
            if(nums[i]!=nums[j]){
                nums[i+1]=nums[j];
                i++;
            }
        }
        return nums.length-j+i+1;
    }

Log in to reply
 

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