方法1:原地修改数组
1 ans = [] 2 for num in nums: 3 if nums[abs(num) - 1] < 0: 4 ans.append(abs(num)) 5 nums[abs(num) - 1] *= - 1 6 return ans
方法2:添加偏置量
1 res = [] 2 for num in nums: 3 if nums[(num%10000)-1] > 10000: 4 res.append(num%10000) 5 else: 6 nums[(num%10000)-1] += 10000 7 return res
标签:10000,abs,nums,重复,442,num%,num,数组,res From: https://www.cnblogs.com/wanxueyu/p/16741997.html