1. 题目
2. 分析
3. 代码
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
if len(nums) < 3:
return len(nums)
i = 0
j = 1
k = 2
while(k < len(nums)):
if (nums[i] == nums[j]):
while(k < len(nums) and nums[j] == nums[k] ):
k+=1
if (k < len(nums)):
j+=1
i+=1
nums[j] = nums[k]
k+=1
else:
j+=1
i+=1
nums[j] = nums[k]
k+=1
return j+1