```
public class Solution {
public int removeDuplicates(int[] nums) {
if (nums == null || nums.length == 0){
return 0;
}
int idx = 0;
for (int i = 0; i < nums.length; i++){
int ref = nums[i];
int j = i+1;
while (j < nums.length && nums[j] == ref){
j++;
}
nums[idx++] = ref;
i = j - 1;
}
return idx;
}
}
```