Skip to content

Commit bb19848

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

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
fun findDuplicates(nums: IntArray): List<Int> {
3+
val res = mutableListOf<Int> ()
4+
5+
for (n in nums) {
6+
val n = if (n < 0) -n else n
7+
if (nums[n - 1] < 0) res.add(n)
8+
nums[n - 1] *= -1
9+
}
10+
11+
return res
12+
}
13+
}

0 commit comments

Comments
 (0)