From d022e736fe637dba893917376c8f87c437eb4b93 Mon Sep 17 00:00:00 2001 From: mykoo Date: Mon, 12 Aug 2024 18:16:30 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[=EA=B5=AC=EB=AC=B8=EC=98=81]=20Week1=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contains-duplicate/GUMUNYEONG.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 contains-duplicate/GUMUNYEONG.js diff --git a/contains-duplicate/GUMUNYEONG.js b/contains-duplicate/GUMUNYEONG.js new file mode 100644 index 000000000..694118a71 --- /dev/null +++ b/contains-duplicate/GUMUNYEONG.js @@ -0,0 +1,14 @@ +/** + * @param {number[]} nums + * @return {boolean} + */ +var containsDuplicate = function (nums) { + const setObj = new Set(nums); + + const diff = !(nums.length === setObj.size); + + return diff; +}; + +// TC: O(n) +// SC: O(n) \ No newline at end of file From f3b80dc6ce476dcc594c0b6465e61c869824f4d9 Mon Sep 17 00:00:00 2001 From: mykoo Date: Tue, 13 Aug 2024 15:14:04 +0900 Subject: [PATCH 2/6] GUMUNYEONG : number-of-1-bit solution --- number-of-1-bits/GUMUNYEONG.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 number-of-1-bits/GUMUNYEONG.js diff --git a/number-of-1-bits/GUMUNYEONG.js b/number-of-1-bits/GUMUNYEONG.js new file mode 100644 index 000000000..af5e4cff6 --- /dev/null +++ b/number-of-1-bits/GUMUNYEONG.js @@ -0,0 +1,17 @@ +/** + * @param {number} n + * @return {number} + */ +var hammingWeight = function (n) { + let i = "1"; + + while (n > 2) { + n % 2 ? i += "1" : ""; + n = Math.floor(n / 2); + } + + return i.length; +}; + +// TC: O(log n) +// SC: O(log n) \ No newline at end of file From 49339cc2522c20286200e1d974101aa4084693ce Mon Sep 17 00:00:00 2001 From: mykoo Date: Tue, 13 Aug 2024 15:16:53 +0900 Subject: [PATCH 3/6] =?UTF-8?q?GUMUNYEONG=20:=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=EC=A4=84=20=EA=B0=9C=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- number-of-1-bits/GUMUNYEONG.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/number-of-1-bits/GUMUNYEONG.js b/number-of-1-bits/GUMUNYEONG.js index af5e4cff6..c82f12c5a 100644 --- a/number-of-1-bits/GUMUNYEONG.js +++ b/number-of-1-bits/GUMUNYEONG.js @@ -14,4 +14,4 @@ var hammingWeight = function (n) { }; // TC: O(log n) -// SC: O(log n) \ No newline at end of file +// SC: O(log n) From 374f84338c1a09ee68a7784a22e0315ead563841 Mon Sep 17 00:00:00 2001 From: mykoo Date: Wed, 14 Aug 2024 16:46:49 +0900 Subject: [PATCH 4/6] GUMUNYEONG.js : top-k-frequent-elements solution --- top-k-frequent-elements/GUMUNYEONG.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 top-k-frequent-elements/GUMUNYEONG.js diff --git a/top-k-frequent-elements/GUMUNYEONG.js b/top-k-frequent-elements/GUMUNYEONG.js new file mode 100644 index 000000000..0ac4a6f09 --- /dev/null +++ b/top-k-frequent-elements/GUMUNYEONG.js @@ -0,0 +1,22 @@ +/** + * @param {number[]} nums + * @param {number} k + * @return {number[]} + */ +var topKFrequent = function (nums, k) { + let result = []; + let fObj = {}; + + for (let i = 0; i < nums.length; i++) { + const n = nums[i]; + fObj[n] ? fObj[n]++ : fObj[n] = 1; + } + + Object + .entries(fObj) + .sort((a, b) => b[1] - a[1]) + .slice(0, k) + .filter(v => result.push(v[0])); + + return result; +}; From 5ae087302615105fc062798f922a46ff3cadc0f8 Mon Sep 17 00:00:00 2001 From: GUMUNYEONG Date: Sun, 18 Aug 2024 11:40:21 +0900 Subject: [PATCH 5/6] =?UTF-8?q?GUMUNYEONG=20:=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=EC=A4=84=20=EA=B0=9C=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contains-duplicate/GUMUNYEONG.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contains-duplicate/GUMUNYEONG.js b/contains-duplicate/GUMUNYEONG.js index 694118a71..fca1f6f68 100644 --- a/contains-duplicate/GUMUNYEONG.js +++ b/contains-duplicate/GUMUNYEONG.js @@ -11,4 +11,4 @@ var containsDuplicate = function (nums) { }; // TC: O(n) -// SC: O(n) \ No newline at end of file +// SC: O(n) From 7934db91235337845629d0b861c9f4910edd2c34 Mon Sep 17 00:00:00 2001 From: mykoo Date: Mon, 19 Aug 2024 11:59:03 +0900 Subject: [PATCH 6/6] =?UTF-8?q?number-of-1-bits=20SC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- number-of-1-bits/GUMUNYEONG.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/number-of-1-bits/GUMUNYEONG.js b/number-of-1-bits/GUMUNYEONG.js index c82f12c5a..02805653b 100644 --- a/number-of-1-bits/GUMUNYEONG.js +++ b/number-of-1-bits/GUMUNYEONG.js @@ -14,4 +14,4 @@ var hammingWeight = function (n) { }; // TC: O(log n) -// SC: O(log n) +// SC: O(1)