Based on https://leetcode.com/discuss/33211/simple-python-solution-o-n

```
class Solution:
# @param {integer[]} nums
# @return {integer}
def removeDuplicates(self, nums):
if len(nums) <3:
return len(nums)
tail = 1
for i in range(2,len(nums)):
if nums[tail] != nums[i] or nums[tail] !=nums[tail-1]:
tail = tail +1
nums[tail] = nums[i]
return tail+1
```