Skip to content

Commit b0e37bc

Browse files
committed
docs: Add comments to problem solving
1 parent f3d0259 commit b0e37bc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

โ€Žcontains-duplicate/mike2ox.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
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+
*/
111
function containsDuplicate(nums: number[]): boolean {
12+
// ์ค‘๋ณต๋œ ๊ฐ’์ด ์—†๋Š” ์ž๋ฃŒ๊ตฌ์กฐ Set ํ™œ์šฉ
213
const set = new Set<number>(nums);
14+
// Set์˜ size์™€ nums์˜ length๋ฅผ ๋น„๊ตํ•˜์—ฌ ์ค‘๋ณต๋œ ๊ฐ’์ด ์žˆ๋Š”์ง€ ํ™•์ธ
315
return set.size !== nums.length;
416
}

0 commit comments

Comments
ย (0)