Find All Duplicates in an Array
Last updated
Last updated
class Solution(object):
def findDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
hashmap=collections.Counter(nums)
return [i for i in hashmap if hashmap[i]>1] def findDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
result =[]
for num in nums:
if nums[abs(num)-1] > 0:
nums[abs(num)-1] = -nums[abs(num)-1]
else:
result.append(abs(num))
return result