```
public class Solution {
public int removeDuplicates(int[] nums) {
int n = nums.length;
if ((n == 0) || (n == 1)) return n;
int lastInt = nums[0];
int lastIndex = 1;
// Run through all items in the list
for (int i = 1; i < n; i++) {
if (nums[i] != lastInt) {
nums[lastIndex] = nums[i];
lastInt = nums[i];
lastIndex++;
}
}
// Return length
return lastIndex;
}
}
```