From 9983c7446807bfe2e96780422079763b01205c11 Mon Sep 17 00:00:00 2001 From: NovaCat Date: Mon, 30 Nov 2026 11:41:34 +0900 Subject: [PATCH 01/13] Resolved: merge-two-sorted-lists#224 --- merge-two-sorted-lists/novacat25.ts | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 merge-two-sorted-lists/novacat25.ts diff --git a/merge-two-sorted-lists/novacat25.ts b/merge-two-sorted-lists/novacat25.ts new file mode 100644 index 0000000000..5fbe01d824 --- /dev/null +++ b/merge-two-sorted-lists/novacat25.ts @@ -0,0 +1,83 @@ +/* +핵심 팁 +문제에서 주어지는 list1 = [1,2,4] 및 list2 = [1,3,4]는 그대로 배열을 쓰는 것이 아니다!! (constructor 부분 주목) +const list1 = new ListNode(1, new ListNode(2, new ListNode(4))) // [1] -> [2] -> [4] -> null +const list2 = new ListNode(1, new ListNode(3, new ListNode(4))) // [1] -> [3] -> [4] -> null +*/ + +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 + } +} + +/* +[2차 풀이] +시간 복잡도: O(n + m) +공간 복잡도: O(n + m) -> O(1) +풀이 기법: Iterative(Dummy Node)로 문제 분해 + Call Stack 기법 대신 객체 참조(Reference)와 포인터 이동을 통해 공간 복잡도를 절약함. +풀이 원리: +(1) tail.next = list1 or list2로 dummy의 객체 속성을 변경시킨다. +(2) list1 = list1.next or list2 = list2.next로 입력 리스트의 참조를 이동한다. +(3) tail = tail.next로 결과 리스트의 참조를 이동한다. + +이 과정에서 dummy는 시작 위치를 그대로 저장하고 있는다. + */ + +const mergeTwoLists = ( + list1: ListNode | null, + list2: ListNode | null, +): ListNode | null => { + const dummyNode = new ListNode(0) + let tail = dummyNode + + 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 + const answerNode = dummyNode.next + + return answerNode +} + +/* +[1차 풀이] +시간 복잡도: O(n + m) +공간 복잡도: O(n + m) +풀이 기법: Recursion + +Self Feedback: +- 최초 풀이에서는 Linked List의 구조 및 재귀적 문제 분해에 대한 이해 부족으로 아이디어를 독립적으로 도출하지 못했다. +- 외부 해설에서 원리를 참고한 뒤 직접 구현하여 정답에 도달했다. +- 이후 ListNode의 constructor와 객체 참조를 확인하며 자료구조에 대한 이해를 보완했다. +- 손풀이를 통해 재귀 호출의 인자 변화, Base case 및 반환 과정까지 추적했다. +- 추후 해설 없이 재귀 풀이를 재구현할 필요가 있다. + */ + +// const mergeTwoLists = ( +// list1: ListNode | null, +// list2: ListNode | null, +// ): ListNode | null => { +// // Base cases +// if (!list1) return list2 +// if (!list2) return list1 + +// if (list1.val <= list2.val) { +// list1.next = mergeTwoLists(list1.next, list2) +// return list1 +// } else { +// list2.next = mergeTwoLists(list1, list2.next) +// return list2 +// } +// } From c13c94f7b12b997efe1a567d870e973b9d53dd6f Mon Sep 17 00:00:00 2001 From: NovaCat Date: Mon, 30 Nov 2026 13:49:00 +0900 Subject: [PATCH 02/13] Resolved: Maximum Depth of Binary Tree #227 --- maximum-depth-of-binary-tree/novacat25.ts | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 maximum-depth-of-binary-tree/novacat25.ts diff --git a/maximum-depth-of-binary-tree/novacat25.ts b/maximum-depth-of-binary-tree/novacat25.ts new file mode 100644 index 0000000000..ffa3f78499 --- /dev/null +++ b/maximum-depth-of-binary-tree/novacat25.ts @@ -0,0 +1,51 @@ +/* +[2차 풀이] +시간 복잡도(TC): O(n) +공간 복잡도(SC): O(n) +풀이: BFS와 Queue를 이용해, 수평 방향으로 우선하여 탐색한다. Queue는 발견했지만 탐색되지 않은 노드열이다. +*/ +const isQueueEmpty = (queue: TreeNode[]) => queue.length === 0 + +const maxDepth = (root: TreeNode | null): number => { + const DEFAULT_VALUE = 0 + if (!root) return DEFAULT_VALUE + + let queue = [root] + let depth = 0 + + while (!isQueueEmpty(queue)) { + let levelSize = queue.length + + for (let i = 0; i < levelSize; i++) { + const currentNode = queue.shift() + + if (currentNode?.left) { + queue.push(currentNode.left) + } + + if (currentNode?.right) { + queue.push(currentNode.right) + } + } + + depth++ + } + + return depth +} + +/* +[1차 풀이] +시간 복잡도(TC): O(n) +공간 복잡도(SC): O(h) - h는 Tree의 높이 +풀이: 재귀 코드를 활용하여, root 기준으로 left/right를 전개하여 풀어나간다. root가 존재하지 않는 기본값은 0으로, Math.max(left, right) 후 추가로 높이 보정치인 1을 더한다. +*/ +// const maxDepth = (root: TreeNode | null): number => { +// const DEFAULT_VALUE = 0 + +// if (!root) return DEFAULT_VALUE +// let leftHeight = maxDepth(root.left) +// let rightHeight = maxDepth(root.right) + +// return Math.max(leftHeight, rightHeight) + 1 +// } From b05f136eb8e99c348ddbe4b8f934c005fbcedfab Mon Sep 17 00:00:00 2001 From: NovaCat Date: Mon, 30 Nov 2026 13:51:34 +0900 Subject: [PATCH 03/13] Fix: TreeNode definition --- maximum-depth-of-binary-tree/novacat25.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/maximum-depth-of-binary-tree/novacat25.ts b/maximum-depth-of-binary-tree/novacat25.ts index ffa3f78499..a13d7a1c43 100644 --- a/maximum-depth-of-binary-tree/novacat25.ts +++ b/maximum-depth-of-binary-tree/novacat25.ts @@ -4,6 +4,17 @@ 공간 복잡도(SC): O(n) 풀이: BFS와 Queue를 이용해, 수평 방향으로 우선하여 탐색한다. Queue는 발견했지만 탐색되지 않은 노드열이다. */ +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 + } +} + const isQueueEmpty = (queue: TreeNode[]) => queue.length === 0 const maxDepth = (root: TreeNode | null): number => { From 507dc55a27e505eb0c1d4e34b407dab5e4e6b43f Mon Sep 17 00:00:00 2001 From: NovaCat Date: Mon, 30 Nov 2026 13:55:58 +0900 Subject: [PATCH 04/13] Refactor: let -> const(levelSize, queue Array): maximum-depth-of-binary-tree --- maximum-depth-of-binary-tree/novacat25.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maximum-depth-of-binary-tree/novacat25.ts b/maximum-depth-of-binary-tree/novacat25.ts index a13d7a1c43..e71d084b41 100644 --- a/maximum-depth-of-binary-tree/novacat25.ts +++ b/maximum-depth-of-binary-tree/novacat25.ts @@ -21,11 +21,11 @@ const maxDepth = (root: TreeNode | null): number => { const DEFAULT_VALUE = 0 if (!root) return DEFAULT_VALUE - let queue = [root] + const queue = [root] let depth = 0 while (!isQueueEmpty(queue)) { - let levelSize = queue.length + const levelSize = queue.length for (let i = 0; i < levelSize; i++) { const currentNode = queue.shift() From 86bd772221d674fc13df293047ce8ebc1b645065 Mon Sep 17 00:00:00 2001 From: NovaCat Date: Mon, 30 Nov 2026 13:58:40 +0900 Subject: [PATCH 05/13] Refactor: queue -> nodeQueue(maximum-depth-of-binary-tree) --- maximum-depth-of-binary-tree/novacat25.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maximum-depth-of-binary-tree/novacat25.ts b/maximum-depth-of-binary-tree/novacat25.ts index e71d084b41..2a0797c633 100644 --- a/maximum-depth-of-binary-tree/novacat25.ts +++ b/maximum-depth-of-binary-tree/novacat25.ts @@ -21,21 +21,21 @@ const maxDepth = (root: TreeNode | null): number => { const DEFAULT_VALUE = 0 if (!root) return DEFAULT_VALUE - const queue = [root] + const nodeQueue = [root] let depth = 0 - while (!isQueueEmpty(queue)) { - const levelSize = queue.length + while (!isQueueEmpty(nodeQueue)) { + const levelSize = nodeQueue.length for (let i = 0; i < levelSize; i++) { - const currentNode = queue.shift() + const currentNode = nodeQueue.shift() if (currentNode?.left) { - queue.push(currentNode.left) + nodeQueue.push(currentNode.left) } if (currentNode?.right) { - queue.push(currentNode.right) + nodeQueue.push(currentNode.right) } } From 72c6ea02a1b4fd64b9a18054eab70baa63d7d503 Mon Sep 17 00:00:00 2001 From: NovaCat Date: Mon, 30 Nov 2026 15:50:18 +0900 Subject: [PATCH 06/13] Resolved: Find Minimum in Rotated Sorted Array#245 --- .../novacat25.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/novacat25.ts diff --git a/find-minimum-in-rotated-sorted-array/novacat25.ts b/find-minimum-in-rotated-sorted-array/novacat25.ts new file mode 100644 index 0000000000..72c7b54bc2 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/novacat25.ts @@ -0,0 +1,31 @@ +/* +시간 복잡도(TC): O(log n) +공간 복잡도(SC): O(1) +풀이: Binary Search를 이용하여 O(log n) 시간 이내에 답을 구한다. +조건: +- 모든 Item을 Search하는 Linear Search는 시간 복잡도가 O(n)이므로 문제 요구사항을 위배한다. +- 모든 item 값은 unique하다. => 중복된 값이 있는 경우라면 index 연산이 애매해지겠으나, 모든 값이 유일하다면 Binary Search를 일관되게 보장할 수 있다. + +Binary Search를 적용할 수 있는 조건 +- 반드시 해당 배열이 정렬되어 있어야 한다. +- Input Array의 경우에는 완전히 정렬되어 있지는 않으나, 'n번 rotate 후 원래의 배열로 돌아간다 = 2개의 Sort된 배열이 합쳐져 있다'는 조건으로 간주되어 Binary Search 적용이 가능하다. +- 분기는 다음과 같다. + - nums[mid] > nums[right]인 경우 => left ~ mid 구간까지는 더 큰 값이 들어 있는 sorted Array임이 자명하므로, mid까지 포함하지 않고 left = mid + 1로 배제하여 탐색 범위를 크게 줄인다. + - nums[mid] <= nums[right]인 경우 => mid ~ right 구간은 sorted & ascending 상태가 보장된다. minimum value는 mid가 될 수도 있으므로 right 값에 mid를 덮어씌운다. +*/ + +const findMin = (nums: number[]): number => { + let left = 0 + let right = nums.length - 1 + + while (left < right) { + const mid = Math.floor(left + (right - left) / 2) + if (nums[mid] > nums[right]) { + left = mid + 1 + } else { + right = mid + } + } + + return nums[left] +} From c745630fbe4745801e8d99032f1c714795344719 Mon Sep 17 00:00:00 2001 From: NovaCat Date: Tue, 1 Dec 2026 09:31:18 +0900 Subject: [PATCH 07/13] Resolved: Coin Change #269 --- coin-change/novacat25.ts | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 coin-change/novacat25.ts diff --git a/coin-change/novacat25.ts b/coin-change/novacat25.ts new file mode 100644 index 0000000000..81a3dfa057 --- /dev/null +++ b/coin-change/novacat25.ts @@ -0,0 +1,48 @@ +/* +시간 복잡도: O(amount * n) +공간 복잡도: O(amount) +풀이 기법: Dynamic Programming을 이용한다. Greedy Algorithm의 경우, [1,3,4]와 6의 반례에서는 실패하기에 remain = amount - coin 기준으로 Min 값을 반환할 수 있도록 하는 DP를 이용하는 것이 이상적. +*/ +/* 풀이 1: Bottom-up */ +const coinChange = (coins: number[], amount: number): number => { + const INVALID_ANSWER = -1 + const dp: number[] = new Array(amount + 1).fill(Infinity) //Invalid Value: Infinity + dp[0] = 0 + + for (let i = 1; i <= amount; i++) { + for (const coin of coins) { + if (coin <= i) { + dp[i] = Math.min(dp[i], dp[i - coin] + 1) + } + } + } + + return dp[amount] > amount ? INVALID_ANSWER : dp[amount] +} + +/* 풀이 2: Top-Down */ +// // 값을 찾지 못한 경우 -Infinity, 조건 상 성립할 수 없는 경우 Infinity. 그로 인해 답이 없다면 -1을 반환함. +// const NOT_SEARCHED = -Infinity +// const INVALID_ANSWER_CONDITION = Infinity +// const INVALID_ANSWER = -1 + +// const solveCoin = (memo: number[], coins: number[], remaining: number): number => { +// if (remaining === 0) return 0 +// if (remaining < 0) return INVALID_ANSWER_CONDITION +// if (memo[remaining] !== NOT_SEARCHED) return memo[remaining] + +// let minCoins = INVALID_ANSWER_CONDITION + +// for (const coin of coins) { +// const sub = solveCoin(memo, coins, remaining - coin) +// minCoins = Math.min(minCoins, sub + 1) +// } +// memo[remaining] = minCoins +// return minCoins +// } + +// const coinChange = (coins: number[], amount: number): number => { +// const memo: number[] = new Array(amount + 1).fill(NOT_SEARCHED) +// const result = solveCoin(memo, coins, amount) +// return result === INVALID_ANSWER_CONDITION ? INVALID_ANSWER : result +// } From 7b633e13b1813c2709f06c56fee2430bc4d783ab Mon Sep 17 00:00:00 2001 From: NovaCat Date: Tue, 1 Dec 2026 16:20:25 +0900 Subject: [PATCH 08/13] Resolved: Word Search #255 --- word-search/novacat25.ts | 118 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 word-search/novacat25.ts diff --git a/word-search/novacat25.ts b/word-search/novacat25.ts new file mode 100644 index 0000000000..d0fb36fedc --- /dev/null +++ b/word-search/novacat25.ts @@ -0,0 +1,118 @@ +/* +[2차 풀이] +시간 복잡도: O(m * n * 3^l) - m: board의 행, n: board의 열, l: word의 길이 +공간 복잡도: O(l) - l: word의 길이 +풀이 기법: Character Matching + Backtracking. DFS 탐색 중, 현재 좌표의 board[i][j]가 word[idx]와 다르면 더 이상 탐색하지 않고 return한다. 또한, 현재 좌표를 방문한 상태로 표시하여, 상하좌우로 이동하며 dfs 탐색을 이어간다. dfs 탐색이 끝나면, 현재 좌표를 방문하지 않은 상태로 되돌린다. (Backtracking) +풀이 원리: +(1) board의 모든 좌표를 순회하며, dfs 탐색을 시작한다. +(2) dfs 탐색 중, 현재 좌표는 #로 임시로 기록한다. 이는 현재 좌표를 방문한 상태로 표시하기 위함이며, Sentinel Value로 활용되므로 Boundary Check 시에 board[i][j] !== word[idx] 조건을 만족하지 않게 된다. +(3) idx 값이 word.length와 같아지는 경우에는 탐색하지 않고 바로 true로 반환한다. 이는 path의 길이가 word의 길이와 같아졌음을 의미하며, word와 path가 일치함을 보장한다.(배열 idx는 0부터 시작하므로, index + 1이 word.length와 같아지는 경우에는 path의 길이가 word의 길이와 같아진다.) +*/ +const START_INDEX = 0 +const VISITED_POSITION = "#" + +const exist = (board: string[][], word: string): boolean => { + const h = board.length + const w = board[0].length + + const backtrack = (i: number, j: number, idx: number): boolean => { + // 이번 로직의 아이디어: 성공적으로 방문하여 idx 길이가 word.length와 충족 시에 true를 반환하도록 함. + if (idx === word.length) { + return true + } + + //Boundary Check + if (i < 0 || i >= h || j < 0 || j >= w || board[i][j] !== word[idx]) { + return false + } + + // 방문한 값은 Sentinel Value인 #(혹은 . 등의 임의의 값)으로 꽂아두어 기존의 true/false 역할을 대신함. + const temp = board[i][j] + board[i][j] = VISITED_POSITION + + // 수평 및 수직으로 일괄 탐색. Call Stack에 의해 순차적으로 실행됨. + const found = + backtrack(i + 1, j, idx + 1) || + backtrack(i - 1, j, idx + 1) || + backtrack(i, j + 1, idx + 1) || + backtrack(i, j - 1, idx + 1) + + // Backtracking 적용 + board[i][j] = temp + + return found + } + + for (let i = 0; i < h; i++) { + for (let j = 0; j < w; j++) { + if (backtrack(i, j, START_INDEX)) { + return true + } + } + } + return false +} + +/* +[1차 풀이] +시간 복잡도: O(m * n * 4^l) - m: board의 행, n: board의 열, l: word의 길이 +공간 복잡도: O(l) - l: word의 길이 +풀이 기법: DFS + Backtracking. Pruning을 따로 활용하지 않았으나, DFS 탐색 중 word의 길이와 path의 길이가 같아지면 더 이상 탐색하지 않고 return한다. +풀이 원리: +(1) board의 모든 좌표를 순회하며, dfs 탐색을 시작한다. +(2) dfs 탐색 중, 현재 좌표의 board[i][j]를 path에 추가한다. +(3) path의 길이가 word의 길이와 같아지면, path와 word를 비교하여 같으면 true, 다르면 false를 return한다. +(4) path의 길이가 word의 길이보다 작으면, 상하좌우로 이동하며 dfs 탐색을 이어간다. +(5) dfs 탐색이 끝나면, 현재 좌표를 방문하지 않은 상태로 되돌린다. (Backtracking) +(6) board의 모든 좌표를 순회하며, dfs 탐색을 이어간다. dfs 탐색 중, path와 word가 같아지면 true를 return하고, 모든 좌표를 순회했음에도 불구하고 path와 word가 같아지지 않으면 false를 return한다. +*/ +// const DIRECTION_BOARD = [ +// [0, 1], +// [0, -1], +// [1, 0], +// [-1, 0], +// ] +// const INITIAL_PATH = "" + +// const isSameWord = (word: string, path: string) => word === path +// const exist = (board: string[][], word: string): boolean => { +// const h = board.length +// const w = board[0].length + +// const visited: boolean[][] = Array.from({ length: h }, () => +// new Array(w).fill(false), +// ) + +// const dfs = (i: number, j: number, path: string): boolean => { +// path += board[i][j] + +// if (path.length === word.length) { +// return isSameWord(word, path) +// } + +// for (const [di, dj] of DIRECTION_BOARD) { +// const ni = i + di +// const nj = j + dj + +// // Boundary Check +// if (ni >= 0 && ni < h && nj >= 0 && nj < w && !visited[ni][nj]) { +// if (dfs(ni, nj, path)) { +// return true +// } +// } +// } + +// visited[i][j] = false +// return false +// } + +// for (let i = 0; i < h; i++) { +// for (let j = 0; j < w; j++) { +// if (dfs(i, j, INITIAL_PATH)) { +// return true +// } +// } +// } + +// return false +// } From 028f4055880b810d2d1dfd825b3708c5449909f4 Mon Sep 17 00:00:00 2001 From: NovaCat Date: Tue, 1 Dec 2026 17:53:49 +0900 Subject: [PATCH 09/13] Bonus: Word Search #255 --- word-search/novacat25.ts | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/word-search/novacat25.ts b/word-search/novacat25.ts index d0fb36fedc..95fab2d61c 100644 --- a/word-search/novacat25.ts +++ b/word-search/novacat25.ts @@ -1,3 +1,84 @@ +/* +[부록] +시간 복잡도: O(m * n * 3^l) - m: board의 행, n: board의 열, l: word의 길이 +공간 복잡도: O(l) - l: word의 길이 +풀이 기법: 기존의 Character Matching + Backtracking 풀이에서, wordCount Record를 응용해 더 희소한 Character부터 탐색하도록 개선함. (Pruning) +풀이 원리: +(1) board의 모든 좌표를 순회하며, dfs 탐색을 시작한다. +(2) dfs 탐색 중, 현재 좌표는 #로 임시로 기록한다. 이는 현재 좌표를 방문한 상태로 표시하기 위함이며, Sentinel Value로 활용되므로 Boundary Check 시에 board[i][j] !== word[idx] 조건을 만족하지 않게 된다. +(3) idx 값이 word.length와 같아지는 경우에는 탐색하지 않고 바로 true로 반환한다. 이는 path의 길이가 word의 길이와 같아졌음을 의미하며, word와 path가 일치함을 보장한다.(배열 idx는 0부터 시작하므로, index + 1이 word.length와 같아지는 경우에는 path의 길이가 word의 길이와 같아진다.) +*/ +// const START_INDEX = 0 +// const VISITED_POSITION = "#" + +// const reverseWord = (str: string) => str.split("").reverse().join("") +// const getWordCount = (countRecord: Record, alphabet: string) => +// countRecord[alphabet] || 0 + +// const exist = (board: string[][], word: string): boolean => { +// const h = board.length +// const w = board[0].length + +// const boardCount: Record = {} +// for (let i = 0; i < h; i++) { +// for (let j = 0; j < w; j++) { +// boardCount[board[i][j]] = (boardCount[board[i][j]] || 0) + 1 +// } +// } + +// const wordCount: Record = {} +// for (const alphabet of word) { +// wordCount[alphabet] = (wordCount[alphabet] || 0) + 1 +// // 비싼 탐색 수행 전 저렴한 연산으로 불가능한 경우를 제거함. +// if (wordCount[alphabet] > (boardCount[alphabet] || 0)) { +// return false +// } +// } + +// let searchWord = word +// const initialWord = word[0] +// const lastWord = word[word.length - 1] +// if ( +// getWordCount(boardCount, initialWord) > getWordCount(boardCount, lastWord) +// ) { +// searchWord = reverseWord(word) +// } + +// const backtrack = (i: number, j: number, idx: number): boolean => { +// if (idx === searchWord.length) { +// return true +// } + +// //Boundary Check +// if (i < 0 || i >= h || j < 0 || j >= w || board[i][j] !== searchWord[idx]) { +// return false +// } + +// const temp = board[i][j] +// board[i][j] = VISITED_POSITION + +// const found = +// backtrack(i + 1, j, idx + 1) || +// backtrack(i - 1, j, idx + 1) || +// backtrack(i, j + 1, idx + 1) || +// backtrack(i, j - 1, idx + 1) + +// board[i][j] = temp + +// return found +// } + +// for (let i = 0; i < h; i++) { +// for (let j = 0; j < w; j++) { +// if (backtrack(i, j, START_INDEX)) { +// return true +// } +// } +// } + +// return false +// } + /* [2차 풀이] 시간 복잡도: O(m * n * 3^l) - m: board의 행, n: board의 열, l: word의 길이 From 286b964d53d642537c0215de910054e7bbfe5afe Mon Sep 17 00:00:00 2001 From: NovaCat Date: Thu, 3 Dec 2026 13:20:31 +0900 Subject: [PATCH 10/13] Refactor: != -> !==(list2) --- merge-two-sorted-lists/novacat25.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/merge-two-sorted-lists/novacat25.ts b/merge-two-sorted-lists/novacat25.ts index 5fbe01d824..4643d54aa2 100644 --- a/merge-two-sorted-lists/novacat25.ts +++ b/merge-two-sorted-lists/novacat25.ts @@ -34,7 +34,7 @@ const mergeTwoLists = ( const dummyNode = new ListNode(0) let tail = dummyNode - while (list1 !== null && list2 != null) { + while (list1 !== null && list2 !== null) { if (list1.val <= list2.val) { tail.next = list1 list1 = list1.next From 1636c94b1491028cdb869d71d2d9ed8278093668 Mon Sep 17 00:00:00 2001 From: NovaCat Date: Thu, 3 Dec 2026 15:34:01 +0900 Subject: [PATCH 11/13] Refactor: coin-change --- coin-change/novacat25.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/coin-change/novacat25.ts b/coin-change/novacat25.ts index 81a3dfa057..a32dcfcf7f 100644 --- a/coin-change/novacat25.ts +++ b/coin-change/novacat25.ts @@ -5,8 +5,10 @@ */ /* 풀이 1: Bottom-up */ const coinChange = (coins: number[], amount: number): number => { - const INVALID_ANSWER = -1 - const dp: number[] = new Array(amount + 1).fill(Infinity) //Invalid Value: Infinity + const ANSWER_NOT_FOUND = -1 + const INVALID_ANSWER_CONDITION = Infinity + + const dp: number[] = new Array(amount + 1).fill(INVALID_ANSWER_CONDITION) //Invalid Value: Infinity dp[0] = 0 for (let i = 1; i <= amount; i++) { @@ -17,7 +19,7 @@ const coinChange = (coins: number[], amount: number): number => { } } - return dp[amount] > amount ? INVALID_ANSWER : dp[amount] + return dp[amount] > amount ? ANSWER_NOT_FOUND : dp[amount] } /* 풀이 2: Top-Down */ From 8a18e3bc6d9b38426e5269230332b57ba197519a Mon Sep 17 00:00:00 2001 From: NovaCat Date: Sat, 5 Dec 2026 22:10:51 +0900 Subject: [PATCH 12/13] Refactor: make code simpler(merge-two-sorted-lists) --- merge-two-sorted-lists/novacat25.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/merge-two-sorted-lists/novacat25.ts b/merge-two-sorted-lists/novacat25.ts index 4643d54aa2..16d8b59c06 100644 --- a/merge-two-sorted-lists/novacat25.ts +++ b/merge-two-sorted-lists/novacat25.ts @@ -45,10 +45,9 @@ const mergeTwoLists = ( tail = tail.next } - tail.next = list1 !== null ? list1 : list2 - const answerNode = dummyNode.next + tail.next = list1 ?? list2 - return answerNode + return dummyNode.next } /* From 43eb7101ab3594e6932e3b1a1399c8388da1d6b3 Mon Sep 17 00:00:00 2001 From: NovaCat Date: Sat, 5 Dec 2026 22:16:18 +0900 Subject: [PATCH 13/13] Refactor: delete meaningless CONSTANTs --- coin-change/novacat25.ts | 3 +-- word-search/novacat25.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/coin-change/novacat25.ts b/coin-change/novacat25.ts index a32dcfcf7f..3e794ab97b 100644 --- a/coin-change/novacat25.ts +++ b/coin-change/novacat25.ts @@ -5,7 +5,6 @@ */ /* 풀이 1: Bottom-up */ const coinChange = (coins: number[], amount: number): number => { - const ANSWER_NOT_FOUND = -1 const INVALID_ANSWER_CONDITION = Infinity const dp: number[] = new Array(amount + 1).fill(INVALID_ANSWER_CONDITION) //Invalid Value: Infinity @@ -19,7 +18,7 @@ const coinChange = (coins: number[], amount: number): number => { } } - return dp[amount] > amount ? ANSWER_NOT_FOUND : dp[amount] + return dp[amount] > amount ? -1 : dp[amount] } /* 풀이 2: Top-Down */ diff --git a/word-search/novacat25.ts b/word-search/novacat25.ts index 95fab2d61c..4d2ce83f4c 100644 --- a/word-search/novacat25.ts +++ b/word-search/novacat25.ts @@ -89,7 +89,6 @@ (2) dfs 탐색 중, 현재 좌표는 #로 임시로 기록한다. 이는 현재 좌표를 방문한 상태로 표시하기 위함이며, Sentinel Value로 활용되므로 Boundary Check 시에 board[i][j] !== word[idx] 조건을 만족하지 않게 된다. (3) idx 값이 word.length와 같아지는 경우에는 탐색하지 않고 바로 true로 반환한다. 이는 path의 길이가 word의 길이와 같아졌음을 의미하며, word와 path가 일치함을 보장한다.(배열 idx는 0부터 시작하므로, index + 1이 word.length와 같아지는 경우에는 path의 길이가 word의 길이와 같아진다.) */ -const START_INDEX = 0 const VISITED_POSITION = "#" const exist = (board: string[][], word: string): boolean => { @@ -126,7 +125,7 @@ const exist = (board: string[][], word: string): boolean => { for (let i = 0; i < h; i++) { for (let j = 0; j < w; j++) { - if (backtrack(i, j, START_INDEX)) { + if (backtrack(i, j, 0)) { return true } }