use the position of the array as hash, use +- to mark state
class Solution(object):
def findDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
res=[]
for num in nums:
if nums[abs(num)-1]<0:
res.append(abs(num))
else:
nums[abs(num)-1]*=-1
return res
网友评论