442. Find All Duplicates in an Array
mediumArray · Hash Table · Sorting
read the problem on leetcode →
first solved 25 Mar 2024
class Solution:
def findDuplicates(self, nums: List[int]) -> List[int]:
ans =[]
n=len(nums)
for x in nums:
x = abs(x)
if nums[x-1]<0:
ans.append(x)
nums[x-1] *= -1
return ans