Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions contains-duplicate/namgiho96.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요, TypeScript 언어에 대한 background가 없어 덕분에 새롭게 찾아보고 알아갑니다. Set을 사용해서 기존 nums와 길이 비교를 하는 방법이 새롭습니다. 이렇게 풀면 O(n)으로 빠른 처리가 가능할 것 같네요. 코드 풀이가 좋아서 배워갑니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @param {number[]} nums
* @return {boolean}
* @Description
* 1. Set을 사용하여 중복된 값을 확인한다.
* 2. Set의 크기가 nums의 길이와 다르면 중복된 값이 있다는 의미이므로 true를 반환한다.
* 3. Set의 크기가 nums의 길이와 같으면 중복된 값이 없다는 의미이므로 false를 반환한다.
*/

function containsDuplicate(nums: number[]): boolean {
return new Set(nums).size !== nums.length;
}