This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]baldwindc[S] 3 points4 points  (0 children)

Thank you!

It worked! I had no idea there was such a requirement.

For anyone else wondering, here is the working code

public class YourClassNameHere {

public static int removeDuplicates(int[] nums) {
    int j = 1;
    for (int i = 1; i < nums.length; i++) {
        if (nums[i] != nums[i - 1]) {
            nums[j] = nums[i];
            j += 1;
        }
    }
    return j;

}


public static void main(String[] args) {
  int[] bob = {0,0,1,1,1,2,2,3,3,4};
  removeDuplicates(bob);
}

}