哈希,记录当前出现的值的次数, 达到 2 次就删除

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param nums int整型一维数组 
# @return int整型
#
from collections import defaultdict
class Solution:
    def removenums(self , nums: List[int]) -> int:
        # write code here
        count = defaultdict(int)
        i = 0
        while i < len(nums):
            if nums[i] in count and count[nums[i]] == 2:
                nums.pop(i)
            else:
                count[nums[i]] += 1
                i += 1
        return len(nums)