From 6c8cc958e6ffa4ad5d7addc4d3f79be0fc460965 Mon Sep 17 00:00:00 2001 From: hyerin Date: Wed, 1 Jan 2025 20:40:34 +0900 Subject: [PATCH 1/8] add: missing-number --- missing-number/HerrineKim.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 missing-number/HerrineKim.js diff --git a/missing-number/HerrineKim.js b/missing-number/HerrineKim.js new file mode 100644 index 000000000..f4b6c780c --- /dev/null +++ b/missing-number/HerrineKim.js @@ -0,0 +1,14 @@ +// 시간 복잡도: O(n) +// 공간 복잡도: O(1) + +/** + * @param {number[]} nums + * @return {number} + */ +var missingNumber = function(nums) { + for(let i = 0; i <= nums.length; i++) { + if (!(nums.includes(i))) { + return i + } + } +}; \ No newline at end of file From e6cab9849db226f8b5f359f59ec186559f50f1ac Mon Sep 17 00:00:00 2001 From: hyerin Date: Wed, 1 Jan 2025 20:43:41 +0900 Subject: [PATCH 2/8] fix: lint --- missing-number/HerrineKim.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/missing-number/HerrineKim.js b/missing-number/HerrineKim.js index f4b6c780c..0bac64bd0 100644 --- a/missing-number/HerrineKim.js +++ b/missing-number/HerrineKim.js @@ -11,4 +11,5 @@ var missingNumber = function(nums) { return i } } -}; \ No newline at end of file +}; + From 021d8fe3386e52dd41585a6c955fd144a99b2b2f Mon Sep 17 00:00:00 2001 From: hyerin Date: Wed, 1 Jan 2025 20:44:59 +0900 Subject: [PATCH 3/8] =?UTF-8?q?fix:=20=EC=8B=9C=EA=B0=84=20=EB=B3=B5?= =?UTF-8?q?=EC=9E=A1=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- missing-number/HerrineKim.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/missing-number/HerrineKim.js b/missing-number/HerrineKim.js index 0bac64bd0..2d7292998 100644 --- a/missing-number/HerrineKim.js +++ b/missing-number/HerrineKim.js @@ -1,4 +1,4 @@ -// 시간 복잡도: O(n) +// 시간 복잡도: O(n^2) // 공간 복잡도: O(1) /** From 3ce15270f09a8dfdb541da7591458d0d60fcecbc Mon Sep 17 00:00:00 2001 From: hyerin Date: Wed, 1 Jan 2025 20:58:16 +0900 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=EC=8B=9C=EA=B0=84=20=EB=B3=B5?= =?UTF-8?q?=EC=9E=A1=EB=8F=84=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- missing-number/HerrineKim.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/missing-number/HerrineKim.js b/missing-number/HerrineKim.js index 2d7292998..6a9122473 100644 --- a/missing-number/HerrineKim.js +++ b/missing-number/HerrineKim.js @@ -1,15 +1,17 @@ -// 시간 복잡도: O(n^2) -// 공간 복잡도: O(1) +// 시간 복잡도: O(n) +// 공간 복잡도: O(n) /** * @param {number[]} nums * @return {number} */ var missingNumber = function(nums) { - for(let i = 0; i <= nums.length; i++) { - if (!(nums.includes(i))) { - return i - } + const numSet = new Set(nums); + + for (let i = 0; i <= nums.length; i++) { + if (!numSet.has(i)) { + return i; + } } }; From 6ccf94cdb123fc9bb108388e468dc5a973be92d4 Mon Sep 17 00:00:00 2001 From: hyerin Date: Sat, 4 Jan 2025 12:32:13 +0900 Subject: [PATCH 5/8] =?UTF-8?q?add:=20=EA=B0=80=EC=9A=B0=EC=8A=A4=20?= =?UTF-8?q?=EA=B3=B5=EC=8B=9D=20=EC=82=AC=EC=9A=A9=ED=95=B4=20=EA=B3=B5?= =?UTF-8?q?=EA=B0=84=20=EB=B3=B5=EC=9E=A1=EB=8F=84=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- missing-number/HerrineKim.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/missing-number/HerrineKim.js b/missing-number/HerrineKim.js index 6a9122473..0742925b8 100644 --- a/missing-number/HerrineKim.js +++ b/missing-number/HerrineKim.js @@ -1,17 +1,17 @@ // 시간 복잡도: O(n) -// 공간 복잡도: O(n) +// 공간 복잡도: O(1) /** * @param {number[]} nums * @return {number} */ var missingNumber = function(nums) { - const numSet = new Set(nums); - - for (let i = 0; i <= nums.length; i++) { - if (!numSet.has(i)) { - return i; - } - } + const n = nums.length; + // 0부터 n까지의 합 공식: n * (n + 1) / 2 + const expectedSum = (n * (n + 1)) / 2; + // 실제 배열의 합 + const actualSum = nums.reduce((sum, num) => sum + num, 0); + + return expectedSum - actualSum; }; From 0716dae46ba8a34041350c0dc6df90a51f84b839 Mon Sep 17 00:00:00 2001 From: hyerin Date: Sat, 4 Jan 2025 12:56:21 +0900 Subject: [PATCH 6/8] add: coin-change --- coin-change/HerrineKim.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 coin-change/HerrineKim.js diff --git a/coin-change/HerrineKim.js b/coin-change/HerrineKim.js new file mode 100644 index 000000000..d393050c3 --- /dev/null +++ b/coin-change/HerrineKim.js @@ -0,0 +1,20 @@ +// 시간 복잡도: O(n * m) +// 공간 복잡도: O(n) + +/** + * @param {number[]} coins + * @param {number} amount + * @return {number} + */ +var coinChange = function(coins, amount) { + const dp = new Array(amount + 1).fill(Infinity); + dp[0] = 0; + + for (let coin of coins) { + for (let i = coin; i <= amount; i++) { + dp[i] = Math.min(dp[i], dp[i - coin] + 1); + } + } + + return dp[amount] === Infinity ? -1 : dp[amount]; +}; From a7eff01c3f563b32fba44b26f42f97b6c2caecdb Mon Sep 17 00:00:00 2001 From: hyerin Date: Sat, 4 Jan 2025 12:56:28 +0900 Subject: [PATCH 7/8] fix: lint --- coin-change/HerrineKim.js | 1 + 1 file changed, 1 insertion(+) diff --git a/coin-change/HerrineKim.js b/coin-change/HerrineKim.js index d393050c3..de894daca 100644 --- a/coin-change/HerrineKim.js +++ b/coin-change/HerrineKim.js @@ -18,3 +18,4 @@ var coinChange = function(coins, amount) { return dp[amount] === Infinity ? -1 : dp[amount]; }; + From e051a94036bd6b1b9eb32e3764f1d8d68d52cf5c Mon Sep 17 00:00:00 2001 From: hyerin Date: Sat, 4 Jan 2025 13:35:50 +0900 Subject: [PATCH 8/8] add: palindromic-substrings --- palindromic-substrings/HerrineKim.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 palindromic-substrings/HerrineKim.js diff --git a/palindromic-substrings/HerrineKim.js b/palindromic-substrings/HerrineKim.js new file mode 100644 index 000000000..b0b563909 --- /dev/null +++ b/palindromic-substrings/HerrineKim.js @@ -0,0 +1,25 @@ +// 시간 복잡도: O(n^2) +// 공간 복잡도: O(1) + +/** + * @param {string} s + * @return {number} + */ +var countSubstrings = function(s) { + let count = 0; + + const countPalindrome = (left, right) => { + while (left >= 0 && right < s.length && s[left] === s[right]) { + count++; + left--; + right++; + } + }; + + for (let i = 0; i < s.length; i++) { + countPalindrome(i, i); + countPalindrome(i, i + 1); + } + + return count; +};