題目
鏈接
思路
雙指針
我好聰明啊,自己想出了這個雙指針的辦法,哈哈哈哈哈哈哈,太高興了
代碼
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)