java solution with two-pointer technique


  • 1
    C

    public static int removeDuplicates(int[] nums){

       if(nums.length==0) return 0;
       int index =0;
       for(int i=1; i<nums.length; i++){
            if(nums[i]!=nums[index]){
                nums[++index] = nums[i];
            }
      }
      return index+1;

Log in to reply
 

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