class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums) == 0: return 0 count = 1 j = 0 for i in range(1, len(nums)): if nums[i] != nums[j]: j += 1 nums[j] = nums[i] count = 1 else: if count >= 2: continue else: j += 1 nums[j] = nums[i] count += 1 del nums[j+1:len(nums)] return len(nums)