原來leetcode使用Count也不需要import collections
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
# len =0
if len(nums) == 0:
return 0
# else
countList = Counter(nums)
countModify = {key:min(value,2) for key,value in countList.items()}
ret = [key for key,value in countModify.items() for _ in range(value)]
nums[:] = ret
return len(nums)