Skip to content

Commit 842f1fc

Browse files
author
이연수
committed
contains-duplicate
1 parent 8901b1d commit 842f1fc

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+
package leetcode_study
2+
3+
/**
4+
* Set 자료 구조로 변경 후 원소의 개수를 비교해 문제 해결
5+
* 시간 복잡도 : O(n)
6+
* -> 모든 Array의 원소를 순회해야함.
7+
* 공간 복잡도 : O(n)
8+
* -> IntArray의 요소 개수에 비례하여 추가적인 공간이 필요함.
9+
*/
10+
fun containsDuplicate(nums: IntArray): Boolean {
11+
val changeSet = nums.toSet()
12+
return changeSet.size != nums.size
13+
}

0 commit comments

Comments
 (0)