From 5eddbc3ea6dc9d12411281cef48928ec6169a2b7 Mon Sep 17 00:00:00 2001 From: Dahm <60846068+j2h30728@users.noreply.github.com> Date: Sun, 19 Jul 2026 14:13:21 +0900 Subject: [PATCH 1/5] week4: 104. Maximum Depth of Binary tree --- maximum-depth-of-binary-tree/j2h30728.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 maximum-depth-of-binary-tree/j2h30728.ts diff --git a/maximum-depth-of-binary-tree/j2h30728.ts b/maximum-depth-of-binary-tree/j2h30728.ts new file mode 100644 index 0000000000..55fbf998ca --- /dev/null +++ b/maximum-depth-of-binary-tree/j2h30728.ts @@ -0,0 +1,20 @@ +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ + +function maxDepth(root: TreeNode | null): number { + if(!root) return 0; + const maxLeft = maxDepth(root.left); + const maxRight = maxDepth(root.right); + return Math.max(maxLeft, maxRight) + 1; +}; \ No newline at end of file From b5a3e0211d350c2d0089bc7232da100beaac8885 Mon Sep 17 00:00:00 2001 From: Dahm <60846068+j2h30728@users.noreply.github.com> Date: Sun, 19 Jul 2026 16:31:30 +0900 Subject: [PATCH 2/5] week4: 21. Merge Two Sorted Lists --- merge-two-sorted-lists/j2h30728.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 merge-two-sorted-lists/j2h30728.ts diff --git a/merge-two-sorted-lists/j2h30728.ts b/merge-two-sorted-lists/j2h30728.ts new file mode 100644 index 0000000000..b7d3849ba9 --- /dev/null +++ b/merge-two-sorted-lists/j2h30728.ts @@ -0,0 +1,29 @@ +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ + +function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode | null { + const root = new ListNode(); + let tail = root; + + while(list1 !== null && list2 !== null){ + if(list1.val <= list2.val){ + tail.next = list1; + list1 = list1.next; + }else{ + tail.next = list2; + list2 = list2.next; + } + tail = tail.next; + } + tail.next = list1 !== null ? list1 : list2; + return root.next; +}; \ No newline at end of file From 2d35b9144717d8018b88cb07c7bf368eb65e21ab Mon Sep 17 00:00:00 2001 From: Dahm <60846068+j2h30728@users.noreply.github.com> Date: Sun, 19 Jul 2026 16:34:54 +0900 Subject: [PATCH 3/5] week4: 153. Find Minimum in Rotated Sorted Array --- find-minimum-in-rotated-sorted-array/j2h30728.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/j2h30728.ts diff --git a/find-minimum-in-rotated-sorted-array/j2h30728.ts b/find-minimum-in-rotated-sorted-array/j2h30728.ts new file mode 100644 index 0000000000..9a24f862b3 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/j2h30728.ts @@ -0,0 +1,12 @@ +function findMin(nums: number[]): number { + const n = nums.length - 1; + let last = nums[n]; + let left = 0, right = n; + + while(left < right){ + const mid = (left + right) >> 1; + if(nums[mid] > last) left = mid + 1; + else right = mid; + } + return nums[left]; +}; \ No newline at end of file From d0b93d31e00a0c5f7b116972e61eac3e3f933efe Mon Sep 17 00:00:00 2001 From: Dahm <60846068+j2h30728@users.noreply.github.com> Date: Sun, 19 Jul 2026 16:56:06 +0900 Subject: [PATCH 4/5] week4: 322. Coin Change --- coin-change/j2h30728.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 coin-change/j2h30728.ts diff --git a/coin-change/j2h30728.ts b/coin-change/j2h30728.ts new file mode 100644 index 0000000000..6a97fb59b8 --- /dev/null +++ b/coin-change/j2h30728.ts @@ -0,0 +1,14 @@ +function coinChange(coins: number[], amount: number): number { + const dp = new Array(amount + 1).fill(amount + 1); + dp[0] = 0; + + for (let i = 1; i <= amount; i++) { + for (const coin of coins) { + if (i - coin >= 0) { + dp[i] = Math.min(dp[i], 1 + dp[i - coin]); + } + } + } + + return dp[amount] > amount ? -1 : dp[amount]; +}; \ No newline at end of file From 8bcd582a55acec721815e74c3de84f4b6a5487af Mon Sep 17 00:00:00 2001 From: Dahm <60846068+j2h30728@users.noreply.github.com> Date: Sun, 19 Jul 2026 23:26:53 +0900 Subject: [PATCH 5/5] fix: add trailing newline to week4 solution files --- coin-change/j2h30728.ts | 2 +- find-minimum-in-rotated-sorted-array/j2h30728.ts | 2 +- maximum-depth-of-binary-tree/j2h30728.ts | 2 +- merge-two-sorted-lists/j2h30728.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/coin-change/j2h30728.ts b/coin-change/j2h30728.ts index 6a97fb59b8..4642b1ad9f 100644 --- a/coin-change/j2h30728.ts +++ b/coin-change/j2h30728.ts @@ -11,4 +11,4 @@ function coinChange(coins: number[], amount: number): number { } return dp[amount] > amount ? -1 : dp[amount]; -}; \ No newline at end of file +}; diff --git a/find-minimum-in-rotated-sorted-array/j2h30728.ts b/find-minimum-in-rotated-sorted-array/j2h30728.ts index 9a24f862b3..fbbbe87a70 100644 --- a/find-minimum-in-rotated-sorted-array/j2h30728.ts +++ b/find-minimum-in-rotated-sorted-array/j2h30728.ts @@ -9,4 +9,4 @@ function findMin(nums: number[]): number { else right = mid; } return nums[left]; -}; \ No newline at end of file +}; diff --git a/maximum-depth-of-binary-tree/j2h30728.ts b/maximum-depth-of-binary-tree/j2h30728.ts index 55fbf998ca..724968007d 100644 --- a/maximum-depth-of-binary-tree/j2h30728.ts +++ b/maximum-depth-of-binary-tree/j2h30728.ts @@ -17,4 +17,4 @@ function maxDepth(root: TreeNode | null): number { const maxLeft = maxDepth(root.left); const maxRight = maxDepth(root.right); return Math.max(maxLeft, maxRight) + 1; -}; \ No newline at end of file +}; diff --git a/merge-two-sorted-lists/j2h30728.ts b/merge-two-sorted-lists/j2h30728.ts index b7d3849ba9..bb430b483e 100644 --- a/merge-two-sorted-lists/j2h30728.ts +++ b/merge-two-sorted-lists/j2h30728.ts @@ -26,4 +26,4 @@ function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode } tail.next = list1 !== null ? list1 : list2; return root.next; -}; \ No newline at end of file +};