My Java solution


  • 0
    V
    public int removeDuplicates(int[] nums) {
        int begin = 0;
        if(nums.length <2){
            return nums.length;
        }
        int temp = nums[0];
        for(int i=1;i<nums.length;i++){
            if(nums[i] !=temp) nums[++begin] = nums[i];
            temp=nums[i];
        }
        return begin+1;
    }

Log in to reply
 

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