Skip to content

Commit 26aa877

Browse files
committed
solve: containsDuplicate
1 parent f291ae8 commit 26aa877

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

contains-duplicate/b41-41.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// nums에 중복이 있는 지 확인하는 것
2+
// array써서 시간 통과 못했다가 Set 객체로 변경해서 통과
3+
function containsDuplicate(nums: number[]): boolean {
4+
const numSet = new Set();
5+
6+
for(let num of nums) {
7+
if(numSet.has(num)) {
8+
return true;
9+
} else {
10+
numSet.add(num);
11+
}
12+
}
13+
14+
return false;
15+
};

0 commit comments

Comments
 (0)