From e9f1cb4db3094df902ceb1dbebfc2884a73a39ec Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Tue, 15 Apr 2025 22:15:11 +0900 Subject: [PATCH 1/7] solve(w03): 125. Valid Palindrome --- valid-palindrome/jeongwoo903.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 valid-palindrome/jeongwoo903.js diff --git a/valid-palindrome/jeongwoo903.js b/valid-palindrome/jeongwoo903.js new file mode 100644 index 000000000..6282ed08d --- /dev/null +++ b/valid-palindrome/jeongwoo903.js @@ -0,0 +1,20 @@ +/* +* 시간 복잡도: O(n) +* 공간 복잡도; O(n) +* +* 과정: +* 1. 소문자, 대문자, 숫자만 파싱 +* 2. 소문자로 변환 +* 3. 리버스 스트링과 기본 스트링과 대조 +*/ + +/** + * @param {string} s + * @return {boolean} + */ +var isPalindrome = function(s) { + const parsedString = s.replace(/[^a-zA-Z0-9]/g, ''); + const lowerString = parsedString.toLowerCase(); + const reverseString = lowerString.split("").reverse().join(""); + return reverseString === lowerString; +}; \ No newline at end of file From 534c9c6960d08a9d93b3504ba9cde0cf93ad8baa Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Tue, 15 Apr 2025 22:19:16 +0900 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20=EC=A4=84=EB=B0=94=EA=BF=88=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-palindrome/jeongwoo903.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/valid-palindrome/jeongwoo903.js b/valid-palindrome/jeongwoo903.js index 6282ed08d..3b05727f6 100644 --- a/valid-palindrome/jeongwoo903.js +++ b/valid-palindrome/jeongwoo903.js @@ -17,4 +17,4 @@ var isPalindrome = function(s) { const lowerString = parsedString.toLowerCase(); const reverseString = lowerString.split("").reverse().join(""); return reverseString === lowerString; -}; \ No newline at end of file +}; From 779d845787b8d829bad520c595fcf0f52c64357a Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Fri, 18 Apr 2025 11:34:46 +0900 Subject: [PATCH 3/7] solve(w03): 191. Number of 1 Bits --- number-of-1-bits/jeongwoo903.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 number-of-1-bits/jeongwoo903.js diff --git a/number-of-1-bits/jeongwoo903.js b/number-of-1-bits/jeongwoo903.js new file mode 100644 index 000000000..c919cfe8d --- /dev/null +++ b/number-of-1-bits/jeongwoo903.js @@ -0,0 +1,14 @@ +/* +* 시간 복잡도: O(log n) +* 공간 복잡도; O(log n) +*/ + +/** + * @param {number} n + * @return {number} + */ +var hammingWeight = function(n) { + const dec = n.toString(2); + const parsedBits = [...dec].filter(item => item === '1'); + return parsedBits.length; +}; From 48e375beaafbc764c35ee8838a6c8975f54bb5c1 Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Fri, 18 Apr 2025 11:49:32 +0900 Subject: [PATCH 4/7] solve(w03): 39. Combination Sum --- combination-sum/jeongwoo903.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 combination-sum/jeongwoo903.js diff --git a/combination-sum/jeongwoo903.js b/combination-sum/jeongwoo903.js new file mode 100644 index 000000000..df651c392 --- /dev/null +++ b/combination-sum/jeongwoo903.js @@ -0,0 +1,29 @@ +/* +* k: 후보 수 +* t: target / 최소 숫자 +* 시간 복잡도: O(k^t) +* 공간 복잡도; O(k^t * t) +*/ + +/** + * @param {number[]} candidates + * @param {number} target + * @return {number[][]} + */ + +var combinationSum = function(candidates, target) { + const combine = (sum, path, startIndex) => { + if (sum > target) return []; + if (sum === target) return [path]; + + return candidates + .slice(startIndex) + .flatMap((candidate, i) => + combine(sum + candidate, [...path, candidate], startIndex + i) + ); + }; + + return candidates.flatMap((candidate, i) => + combine(candidate, [candidate], i) + ); +}; From d748504737bc859c8e382be60e140febedc2725b Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Sun, 20 Apr 2025 23:04:53 +0900 Subject: [PATCH 5/7] solve(w03): 91. Decode Ways --- decode-ways/jeongwoo903.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 decode-ways/jeongwoo903.js diff --git a/decode-ways/jeongwoo903.js b/decode-ways/jeongwoo903.js new file mode 100644 index 000000000..cd676b71c --- /dev/null +++ b/decode-ways/jeongwoo903.js @@ -0,0 +1,27 @@ +/* +* 시간 복잡도: O(n) +* 공간 복잡도; O(n) +*/ + +/** + * @param {string} s + * @return {number} + */ +var numDecodings = function(s) { + if (s.length === 0 || s[0] === "0") return 0; + + let dp = new Array(s.length + 1).fill(0); + + dp[0] = 1; + dp[1] = 1; + + for (let i = 2; i <= s.length; i++) { + let single = s[i - 1]; + let double = s[i - 2] + s[i - 1]; + + if (single >= 1 && single <= 9) dp[i] += dp[i - 1]; + if (double >= 10 && double <= 26) dp[i] += dp[i - 2]; + } + + return dp[s.length]; +}; From 57cd63362f6cb69d523fea2bdaeb2f66354c20ce Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Sun, 20 Apr 2025 23:20:13 +0900 Subject: [PATCH 6/7] solve(w03): 53. Maximum Subarray --- maximum-subarray/jeongwoo903.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 maximum-subarray/jeongwoo903.js diff --git a/maximum-subarray/jeongwoo903.js b/maximum-subarray/jeongwoo903.js new file mode 100644 index 000000000..aeac1a0b8 --- /dev/null +++ b/maximum-subarray/jeongwoo903.js @@ -0,0 +1,21 @@ +/* +* 시간 복잡도: O(n) +* 공간 복잡도: O(1) +*/ + +/** + * @param {number[]} nums + * @return {number} + */ +var maxSubArray = function(nums) { + let max = nums[0]; + let result = nums[0]; + + for (let index = 1; index < nums.length; index++) { + const num = nums[index]; + result = Math.max(result + num, num); + max = Math.max(max, result); + } + + return max; +}; \ No newline at end of file From e7c0e902572de0efa87628a969e530c94ddf0a30 Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Sun, 20 Apr 2025 23:21:10 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20=EC=A4=84=EB=B0=94=EA=BF=88=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maximum-subarray/jeongwoo903.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maximum-subarray/jeongwoo903.js b/maximum-subarray/jeongwoo903.js index aeac1a0b8..002e2d030 100644 --- a/maximum-subarray/jeongwoo903.js +++ b/maximum-subarray/jeongwoo903.js @@ -18,4 +18,4 @@ var maxSubArray = function(nums) { } return max; -}; \ No newline at end of file +};