Skip to content

Commit 2b9e65c

Browse files
committed
solve Contains Duplicate
1 parent ec2f957 commit 2b9e65c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

contains-duplicate/acious.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
// 1 <= nums.length <= 10^5
3+
// Integer.MIN_VALUE(2,147,483,647) < -10^9 <= nums[i] <= 10^9 < Integer.MAX_VALUE(2,147,483,647)
4+
// HashSet에 아이템을 하나씩 넣으면서 이미 존재하는 아이템이 있으면 true, 없으면 false
5+
// 시간복잡도 : O(n), 공간복잡도 : O(n)
6+
fun containsDuplicate(nums: IntArray): Boolean {
7+
val set = HashSet<Int>()
8+
for (num in nums) {
9+
if (set.contains(num)) {
10+
return true
11+
}
12+
set.add(num)
13+
}
14+
return false
15+
}
16+
}

0 commit comments

Comments
 (0)