```
public class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length < 2) {
return nums.length;
}
int end = 0;
for(int i = 1; i<nums.length;i++) {
if (nums[end] < nums[i]) {
end++;
nums[end] = nums[i];
}
}
return end+1;
}
}
```