题目
思路
双指针
我好聪明啊,自己想出了这个双指针的办法,哈哈哈哈哈哈哈,太高兴了
代码
python
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n=len(nums)
if n<=1:
return n
left,right=0,0
repeat={}
while right<n:
x=nums[right]
if x not in repeat:
repeat[x]=1
else:
repeat[x]+=1
if repeat[x]<=2:
nums[left]=x
left+=1
right+=1
return left
solution=Solution()
input_content=[0,0,1,1,1,1,2,3,3]
ans=solution.removeDuplicates(input_content)
print(ans)