class Solution(object):
def findDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
for each in set(nums):
nums.remove(each)
return nums
修改后
class Solution(object):
def findDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
res = []
for x in nums:
if nums[int(abs(x)-1)] < 0:
res.append(abs(x))
else:
nums[abs(x)-1] *= -1
return res