From a7974dd25b86d1ffb28929d1ada1dba1220ac993 Mon Sep 17 00:00:00 2001 From: j2h30728 <60846068+j2h30728@users.noreply.github.com> Date: Mon, 29 Jun 2026 21:33:41 +0900 Subject: [PATCH 1/6] week2: 242. Valid Anagram --- valid-anagram/j2h30728.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/valid-anagram/j2h30728.ts b/valid-anagram/j2h30728.ts index 44110f2a3e..326c7e2f29 100644 --- a/valid-anagram/j2h30728.ts +++ b/valid-anagram/j2h30728.ts @@ -1,12 +1,26 @@ +/** + * + * @param s + * @param t + * @returns + * 시간 복잡도 : O(n) + * 공간 복잡도 : O(n) + */ function isAnagram(s: string, t: string): boolean { - const obj = {}; + if (s.length !== t.length) return false; + + const map = new Map(); + for (let i = 0; i < s.length; i++) { - obj[s[i]] = (obj[s[i]] || 0) + 1; + map.set(s[i], (map.get(s[i]) ?? 0) + 1); + map.set(t[i], (map.get(t[i]) ?? 0) - 1); } - for (let i = 0; i < t.length; i++) { - obj[t[i]] -= 1; + for (let ch of map.values()) { + if (ch !== 0) { + return false; + } } - return Object.values(obj).filter((value) => value !== 0).length === 0; + return true; } From e2ff53f12c2aacbb62618eed3cc8057f7e69859d Mon Sep 17 00:00:00 2001 From: j2h30728 <60846068+j2h30728@users.noreply.github.com> Date: Sat, 4 Jul 2026 19:46:11 +0900 Subject: [PATCH 2/6] week2: 70. Climbing Stairs --- climbing-stairs/j2h30728.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/climbing-stairs/j2h30728.ts b/climbing-stairs/j2h30728.ts index cc08c63cea..d7a2e50bda 100644 --- a/climbing-stairs/j2h30728.ts +++ b/climbing-stairs/j2h30728.ts @@ -1,14 +1,18 @@ +/** + * 시간 복잡도 : O(n) + * 공간 복잡도 : O(1) + */ function climbStairs(n: number): number { - if (n === 0 || n === 1) { - return 1; - } + if (n <= 2) return n; - const memo: number[] = []; - memo[0] = memo[1] = 1; + let prev2 = 1; + let prev1 = 2; + let current = 0; - for (let i = 2; i <= n; i++) { - memo[i] = memo[i - 1] + memo[i - 2]; + for (let i = 3; i <= n; i++) { + current = prev2 + prev1; + prev2 = prev1; + prev1 = current; } - - return memo[n]; + return current; } From dc633a3110e526b75721e74adcd96e07c62c5f73 Mon Sep 17 00:00:00 2001 From: j2h30728 <60846068+j2h30728@users.noreply.github.com> Date: Sat, 4 Jul 2026 19:47:44 +0900 Subject: [PATCH 3/6] week2: 238. Product of Array Except Self --- product-of-array-except-self/j2h30728.ts | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/product-of-array-except-self/j2h30728.ts b/product-of-array-except-self/j2h30728.ts index c877204ffc..8bdb2f8ed2 100644 --- a/product-of-array-except-self/j2h30728.ts +++ b/product-of-array-except-self/j2h30728.ts @@ -1,18 +1,21 @@ +/** + * 시간 복잡도 : O(n) + * 공간 복잡도 : O(n) + */ function productExceptSelf(nums: number[]): number[] { - const length = nums.length; - const result = new Array(nums.length).fill(1); + const arr = new Array(nums.length).fill(1); - let leftTemp = 1; - for (let i = 0; i < length; i++) { - result[i] = leftTemp; - leftTemp *= nums[i]; + let left = 1; + for (let i = 0; i < nums.length; i++) { + arr[i] = left; + left *= nums[i]; } - let rightTemp = 1; - for (let i = length - 1; i >= 0; i--) { - result[i] *= rightTemp; - rightTemp *= nums[i]; + let right = 1; + for (let i = nums.length - 1; i >= 0; i--) { + arr[i] *= right; + right *= nums[i]; } - return result; + return arr; } From f1528b4dbf7052a77d2725af252947df4f39740e Mon Sep 17 00:00:00 2001 From: j2h30728 <60846068+j2h30728@users.noreply.github.com> Date: Sat, 4 Jul 2026 19:48:28 +0900 Subject: [PATCH 4/6] week2: 15. 3Sum --- 3sum/j2h30728.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 3sum/j2h30728.ts diff --git a/3sum/j2h30728.ts b/3sum/j2h30728.ts new file mode 100644 index 0000000000..eb49720740 --- /dev/null +++ b/3sum/j2h30728.ts @@ -0,0 +1,46 @@ +/** + * 시간 복잡도 : O(n^2) + * 공간 복잡도 : O(1) + */ +function threeSum(nums: number[]): number[][] { + const result: number[][] = []; + nums.sort((a, b) => a - b); + + for (let i = 0; i < nums.length - 2; i++) { + if (i > 0 && nums[i] === nums[i - 1]) { + continue; + } + + if (nums[i] > 0) { + break; + } + + let left = i + 1; + let right = nums.length - 1; + + while (left < right) { + const sum = nums[i] + nums[left] + nums[right]; + + if (sum === 0) { + result.push([nums[i], nums[left], nums[right]]); + + left++; + right--; + + while (left < right && nums[left] === nums[left - 1]) { + left++; + } + + while (left < right && nums[right] === nums[right + 1]) { + right--; + } + } else if (sum < 0) { + left++; + } else { + right--; + } + } + } + + return result; +} From 3ca4feab9fec99f74f72ce12b1687f6800b45f4b Mon Sep 17 00:00:00 2001 From: j2h30728 <60846068+j2h30728@users.noreply.github.com> Date: Sat, 4 Jul 2026 19:50:42 +0900 Subject: [PATCH 5/6] week2: 98. Validate Binary Search Tree --- validate-binary-search-tree/j2h30728.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/validate-binary-search-tree/j2h30728.ts b/validate-binary-search-tree/j2h30728.ts index bb80ea58be..05efb9d8b8 100644 --- a/validate-binary-search-tree/j2h30728.ts +++ b/validate-binary-search-tree/j2h30728.ts @@ -10,13 +10,14 @@ class TreeNode { } function isValidBST(root: TreeNode | null): boolean { - function valid(node, min, max) { - if (!node) return true; + function validate(node: TreeNode | null, min: number, max: number): boolean { + if (node === null) return true; if (node.val <= min || node.val >= max) return false; - return valid(node.left, min, node.val) && valid(node.right, node.val, max); + return ( + validate(node.left, min, node.val) && validate(node.right, node.val, max) + ); } - - return valid(root, -Infinity, Infinity); + return validate(root, -Infinity, Infinity); } From 73c982d9797f04a2b7c7961be6589dc40d386372 Mon Sep 17 00:00:00 2001 From: j2h30728 <60846068+j2h30728@users.noreply.github.com> Date: Sun, 5 Jul 2026 03:01:54 +0900 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20=EC=8B=9C=EA=B0=84=EB=B3=B5?= =?UTF-8?q?=EC=9E=A1=EB=8F=84,=20=EA=B3=B5=EA=B0=84=EB=B3=B5=EC=9E=A1?= =?UTF-8?q?=EB=8F=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- product-of-array-except-self/j2h30728.ts | 2 +- validate-binary-search-tree/j2h30728.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/product-of-array-except-self/j2h30728.ts b/product-of-array-except-self/j2h30728.ts index 8bdb2f8ed2..98f20e6c60 100644 --- a/product-of-array-except-self/j2h30728.ts +++ b/product-of-array-except-self/j2h30728.ts @@ -1,6 +1,6 @@ /** * 시간 복잡도 : O(n) - * 공간 복잡도 : O(n) + * 공간 복잡도 : O(1) (출력 배열 제외, left/right 변수만 사용) */ function productExceptSelf(nums: number[]): number[] { const arr = new Array(nums.length).fill(1); diff --git a/validate-binary-search-tree/j2h30728.ts b/validate-binary-search-tree/j2h30728.ts index 05efb9d8b8..9760287ccc 100644 --- a/validate-binary-search-tree/j2h30728.ts +++ b/validate-binary-search-tree/j2h30728.ts @@ -9,6 +9,10 @@ class TreeNode { } } +/** + * 시간 복잡도 : O(n) - 모든 노드를 한 번씩 방문 + * 공간 복잡도 : O(h) - 재귀 호출 스택 깊이 (h는 트리 높이, 최악의 경우 O(n)) + */ function isValidBST(root: TreeNode | null): boolean { function validate(node: TreeNode | null, min: number, max: number): boolean { if (node === null) return true;