Skip to content

Commit 407b10e

Browse files
committed
add: solve #217 Contains Duplicate with ts
1 parent b8b7c86 commit 407b10e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

contains-duplicate/YJason-K.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Set 자료구조를 사용하여 중복 확인 (시간 복잡도: O(n) )
3+
* @param nums 중복 검사할 숫자 배열
4+
* @returns boolean 중복 여부
5+
*/
6+
7+
function containsDuplicate(nums: number[]): boolean {
8+
let unique: Set<number> = new Set([]);
9+
for (const num of nums) {
10+
if (unique.has(num)) {
11+
return true
12+
} else {
13+
unique.add(num)
14+
}
15+
}
16+
return false;
17+
};

0 commit comments

Comments
 (0)