We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ae344e8 commit 2beb39eCopy full SHA for 2beb39e
โcontains-duplicate/seungseung88.jsโ
@@ -0,0 +1,21 @@
1
+// ์๊ฐ ๋ณต์ก๋: O(n) => ๋ฐฐ์ด์ ํ ๋ฒ๋ง ์ํํ๋ฏ๋ก
2
+// ๊ณต๊ฐ ๋ณต์ก๋: O(n) => ์ต์ ์ ๊ฒฝ์ฐ ๋ชจ๋ ์์๋ฅผ ๊ฐ์ฒด์ ์ ์ฅํ๋ฏ๋ก
3
+const containsDuplicate = (nums) => {
4
+ const indices = {};
5
+
6
+ // ๋ฐฐ์ด์ ํ ๋ฒ ์ํ
7
+ for (let i = 0; i < nums.length; i += 1) {
8
+ const num = nums[i];
9
10
+ // ์์ง ๋ฑ์ฅํ์ง ์์ ์ซ์๋ผ๋ฉด ๊ฐ์ฒด์ ๊ธฐ๋ก
11
+ if (!indices[num]) {
12
+ indices[num] = 1;
13
+ } else {
14
+ // ์ด๋ฏธ ๋ฑ์ฅํ ์ซ์๋ผ๋ฉด ์ค๋ณต์ด๋ฏ๋ก true ๋ฐํ
15
+ return true;
16
+ }
17
18
19
+ // ์ค๋ณต์ด ์์ผ๋ฉด false ๋ฐํ
20
+ return false;
21
+};
0 commit comments