Skip to content

Commit d395ba2

Browse files
authored
Create 0442-find-all-duplicates-in-an-array.py
1 parent ff1aaf2 commit d395ba2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def findDuplicates(self, nums: List[int]) -> List[int]:
3+
res = []
4+
5+
for n in nums:
6+
n = abs(n)
7+
if nums[n - 1] < 0:
8+
res.append(n)
9+
nums[n - 1] = -nums[n - 1]
10+
11+
return res

0 commit comments

Comments
 (0)