From bde7c97b64e8010deb76032fc50aa3ec3eec2f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A9=E1=84=92=E1=85=A8=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 11 Aug 2025 12:22:19 +0900 Subject: [PATCH 1/5] merge two sorted lists solution --- merge-two-sorted-lists/hyer0705.ts | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 merge-two-sorted-lists/hyer0705.ts diff --git a/merge-two-sorted-lists/hyer0705.ts b/merge-two-sorted-lists/hyer0705.ts new file mode 100644 index 0000000000..cfa0004136 --- /dev/null +++ b/merge-two-sorted-lists/hyer0705.ts @@ -0,0 +1,44 @@ +/** + * 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 { + if (!list1 && !list2) return null; + + if (!list1) return list2; + if (!list2) return list1; + + const dummyHead = new ListNode(-101); + let tail = dummyHead; + + let pointerOne: ListNode | null = list1; + let pointerTwo: ListNode | null = list2; + + while (pointerOne && pointerTwo) { + if (pointerOne.val <= pointerTwo.val) { + tail.next = pointerOne; + pointerOne = pointerOne.next; + } else { + tail.next = pointerTwo; + pointerTwo = pointerTwo.next; + } + + tail = tail.next; + } + + if (pointerOne) { + tail.next = pointerOne; + } else { + tail.next = pointerTwo; + } + + return dummyHead.next; +} From 2eb01724ae41da239241f1cd23faed7c91762b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A9=E1=84=92=E1=85=A8=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 11 Aug 2025 12:39:01 +0900 Subject: [PATCH 2/5] maximum depth of binary tree solution --- maximum-depth-of-binary-tree/hyer0705.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 maximum-depth-of-binary-tree/hyer0705.ts diff --git a/maximum-depth-of-binary-tree/hyer0705.ts b/maximum-depth-of-binary-tree/hyer0705.ts new file mode 100644 index 0000000000..949af17d6d --- /dev/null +++ b/maximum-depth-of-binary-tree/hyer0705.ts @@ -0,0 +1,19 @@ +/** + * 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; + + return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); +} From 2e91cf41aa4392a70ce8192cc92bdff1db4b9f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A9=E1=84=92=E1=85=A8=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 11 Aug 2025 13:01:29 +0900 Subject: [PATCH 3/5] find minimum in rotated sorted array solution --- .../hyer0705.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/hyer0705.ts diff --git a/find-minimum-in-rotated-sorted-array/hyer0705.ts b/find-minimum-in-rotated-sorted-array/hyer0705.ts new file mode 100644 index 0000000000..9714d32be1 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/hyer0705.ts @@ -0,0 +1,18 @@ +function findMin(nums: number[]): number { + const n = nums.length; + + let l = 0; + let r = n - 1; + + while (l < r) { + const mid = Math.floor((l + r) / 2); + + if (nums[r] >= nums[mid]) { + r = mid; + } else if (nums[r] < nums[mid]) { + l = mid + 1; + } + } + + return nums[l]; +} From 29aea9b8d9b37ef5159b218a3bf9e51957a84759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A9=E1=84=92=E1=85=A8=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 11 Aug 2025 13:43:18 +0900 Subject: [PATCH 4/5] word search solution --- word-search/hyer0705.ts | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 word-search/hyer0705.ts diff --git a/word-search/hyer0705.ts b/word-search/hyer0705.ts new file mode 100644 index 0000000000..6433d266cd --- /dev/null +++ b/word-search/hyer0705.ts @@ -0,0 +1,48 @@ +function exist(board: string[][], word: string): boolean { + const m = board.length; + const n = board[0].length; + + const visited: boolean[][] = Array.from({ length: m }, () => Array(n).fill(false)); + + const isValidCoordinates = (index: number, x: number, y: number): boolean => { + if (x >= 0 && x < m && y >= 0 && y < n && word[index] === board[x][y] && !visited[x][y]) return true; + return false; + }; + + const backtrack = (index: number, cx: number, cy: number): boolean => { + if (index === word.length - 1 && board[cx][cy] === word[index]) return true; + + if (board[cx][cy] !== word[index]) return false; + + for (const [dx, dy] of [ + [0, 1], + [0, -1], + [1, 0], + [-1, 0], + ]) { + const [nx, ny] = [cx + dx, cy + dy]; + + if (isValidCoordinates(index + 1, nx, ny)) { + visited[nx][ny] = true; + const result = backtrack(index + 1, nx, ny); + if (result) return true; + visited[nx][ny] = false; + } + } + + return false; + }; + + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + if (board[i][j] === word[0]) { + visited[i][j] = true; + const result: boolean = backtrack(0, i, j); + if (result) return true; + visited[i][j] = false; + } + } + } + + return false; +} From d8780032d311f72ff711bd156760313adbdbbd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A9=E1=84=92=E1=85=A8=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 11 Aug 2025 14:44:17 +0900 Subject: [PATCH 5/5] coin change solution --- coin-change/hyer0705.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 coin-change/hyer0705.ts diff --git a/coin-change/hyer0705.ts b/coin-change/hyer0705.ts new file mode 100644 index 0000000000..4cee4f0104 --- /dev/null +++ b/coin-change/hyer0705.ts @@ -0,0 +1,17 @@ +function coinChange(coins: number[], amount: number): number { + // dp[i] = i 금액을 만드는 데 필요한 최소 동전의 갯수... + const dp: number[] = Array(amount + 1).fill(Infinity); + dp[0] = 0; + + for (let i = 1; i <= amount; i++) { + let min = Infinity; + for (const coin of coins) { + if (i >= coin) { + min = Math.min(dp[i - coin] + 1, min); + } + } + dp[i] = min; + } + + return Number.isFinite(dp[amount]) ? dp[amount] : -1; +}