Skip to content

Commit ff1aaf2

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

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public List<Integer> findDuplicates(int[] nums) {
3+
List<Integer> res = new ArrayList<>();
4+
5+
for (int n : nums) {
6+
n = Math.abs(n);
7+
if (nums[n - 1] < 0)
8+
res.add(n);
9+
nums[n - 1] = -nums[n - 1];
10+
}
11+
12+
return res;
13+
}
14+
}

0 commit comments

Comments
 (0)