Find All Duplicates in an Array LeetCode solution in Python

1
class Solution:
2
def findDuplicates(self, nums: List[int]) -> List[int]:
3
res = []
4
hm = {}
5
# adding entries in hashmap to check frequency
6
for i, v in enumerate(nums):
7
if v not in hm:
8
hm[v] = 1
9
else:
10
hm[v] += 1
11
# checking frequency of item and adding output to an array
12
for key, value in hm.items():
13
if value > 1:
14
res.append(key)
15
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0