The idea here is to move from left to right in array and swapping elements that are duplicates out with elements we find that are not duplicates. If nums[i] and end[i+1] are not equal then we just swap the new element with the first found duplicate (and if there are no duplicates we essentially swap the element with itself for no impact). By the time we reach end of array all the duplicates have been swapped to the back end of array.

```
def removeDuplicates(self, nums):
end = 0
for i in range(1, len(nums)):
if nums[i] != nums[end]:
nums[end+1], nums[i], end = nums[i], nums[end+1], end + 1
return end+1 if nums else 0
```