Skip to content

Commit d1dca31

Browse files
committed
feat(kt/problems): add contains duplicate
1 parent 7f1736f commit d1dca31

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package problems
2+
3+
fun containsDuplicate(nums: IntArray): Boolean {
4+
val seenNumbers = HashSet<Int>()
5+
6+
for (num in nums) {
7+
if (seenNumbers.contains(num)) {
8+
return true
9+
}
10+
seenNumbers.add(num)
11+
}
12+
13+
return false
14+
}
15+
16+
fun main() {
17+
println("Contains Duplicate")
18+
19+
val nums = intArrayOf(1, 1, 1, 3, 3, 4, 3, 2, 4, 2)
20+
21+
println(containsDuplicate(nums))
22+
}

0 commit comments

Comments
 (0)