【LeetCode】删除排序数组中的重复项 II
题目
链接
思路
双指针
我好聪明啊,自己想出了这个双指针的办法,哈哈哈哈哈哈哈,太高兴了
代码
class Solution(object):def removeDuplicates(self, nums):""":type nums: List[int]:rtype: int"""n=len(nums)if n<=1:return nleft,right=0,0repeat={}while right<n:x=nums[right]if x not in repeat:repeat[x]=1else:repeat[x]+=1if repeat[x]<=2:nums[left]=xleft+=1right+=1return leftsolution=Solution()
input_content=[0,0,1,1,1,1,2,3,3]
ans=solution.removeDuplicates(input_content)
print(ans)