File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Source: https://leetcode.com/problems/contains-duplicate/
3
+ * ํ์ด๋ฐฉ๋ฒ: Set์ ์ด์ฉํ์ฌ ์ค๋ณต๋ ๊ฐ์ด ์๋์ง ํ์ธ
4
+ * ์๊ฐ๋ณต์ก๋: O(n)
5
+ * ๊ณต๊ฐ๋ณต์ก๋: O(n)
6
+ *
7
+ * ์๊ฐ๋๋ ํ์ด๋ฐฉ๋ฒ
8
+ * 1. ๋จ์ํ๊ฒ sorted๋ฅผ ์ด์ฉํ์ฌ ์ด์ ๊ฐ๊ณผ ๋น๊ตํ์ฌ ์ค๋ณต๋ ๊ฐ์ด ์๋์ง ํ์ธ
9
+ * 2. ์ ๋ ฌํ์ง ์๊ณ nums์ ๊ธธ์ด๋งํผ์ ๋ฐฐ์ด์ ๋ง๋ค์ด์ ์ค๋ณต๋ ๊ฐ์ด ์๋์ง ์ ์ฅํ๋ฉด์ ํ์ธ
10
+ */
1
11
function containsDuplicate ( nums : number [ ] ) : boolean {
12
+ // ์ค๋ณต๋ ๊ฐ์ด ์๋ ์๋ฃ๊ตฌ์กฐ Set ํ์ฉ
2
13
const set = new Set < number > ( nums ) ;
14
+ // Set์ size์ nums์ length๋ฅผ ๋น๊ตํ์ฌ ์ค๋ณต๋ ๊ฐ์ด ์๋์ง ํ์ธ
3
15
return set . size !== nums . length ;
4
16
}
You canโt perform that action at this time.
0 commit comments