From f562340c6c8c9b7b163268c7681dc01d51c1c2f3 Mon Sep 17 00:00:00 2001 From: casentino Date: Wed, 3 Dec 2025 18:21:58 +0900 Subject: [PATCH 1/5] Merge Two Sorted Lists --- merge-two-sorted-lists/casentino.ts | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 merge-two-sorted-lists/casentino.ts diff --git a/merge-two-sorted-lists/casentino.ts b/merge-two-sorted-lists/casentino.ts new file mode 100644 index 0000000000..98ca57e9f6 --- /dev/null +++ b/merge-two-sorted-lists/casentino.ts @@ -0,0 +1,40 @@ +/** + * 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 list1 ?? list2; + } + function merge(node1: ListNode | null, node2: ListNode | null) { + if (!node1 || !node2) { + return node1 ?? node2; + } + if (node1.val < node2.val) { + node1.next = merge(node1.next, node2); + } + if (node1.val >= node2.val) { + node2.next = merge(node1, node2.next); + } + + return node1.val < node2.val ? node1 : node2; + } + return merge(list1, list2); +} + +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; + } +} From 1878e196b08509ebfe238eec32695bd57cbc2438 Mon Sep 17 00:00:00 2001 From: casentino Date: Wed, 3 Dec 2025 18:29:15 +0900 Subject: [PATCH 2/5] Maximum Depth of Binary Tree --- maximum-depth-of-binary-tree/casentino.ts | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 maximum-depth-of-binary-tree/casentino.ts diff --git a/maximum-depth-of-binary-tree/casentino.ts b/maximum-depth-of-binary-tree/casentino.ts new file mode 100644 index 0000000000..1db084fe6e --- /dev/null +++ b/maximum-depth-of-binary-tree/casentino.ts @@ -0,0 +1,36 @@ +/** + * 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 { + function recursive(node: TreeNode | null, count: number) { + if (!node) { + return count; + } + const left = recursive(node.left, count + 1); + const right = recursive(node.right, count + 1); + return left > right ? left : right; + } + return recursive(root, 0); +} + +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; + } +} From d57a0b12212347bb2e41f1b538a036a4a23d6ccf Mon Sep 17 00:00:00 2001 From: casentino Date: Wed, 3 Dec 2025 19:29:34 +0900 Subject: [PATCH 3/5] Find Minimum in Rotated Sorted Array --- find-minimum-in-rotated-sorted-array/casentino.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/casentino.ts diff --git a/find-minimum-in-rotated-sorted-array/casentino.ts b/find-minimum-in-rotated-sorted-array/casentino.ts new file mode 100644 index 0000000000..856a46a002 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/casentino.ts @@ -0,0 +1,15 @@ +function findMin(nums: number[]): number { + let left = 0; + let right = nums.length - 1; + + while (left < right) { + const middle = Math.floor((left + right) / 2); + + if (nums[middle] < nums[right]) { + right = middle; + } else { + left = middle + 1; + } + } + return nums[left]; +} From 46cebfed012cc09de47583be1096aefffeab566a Mon Sep 17 00:00:00 2001 From: casentino Date: Sun, 7 Dec 2025 01:28:01 +0900 Subject: [PATCH 4/5] Word Search --- word-search/casentino.ts | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 word-search/casentino.ts diff --git a/word-search/casentino.ts b/word-search/casentino.ts new file mode 100644 index 0000000000..e0eae5c7c6 --- /dev/null +++ b/word-search/casentino.ts @@ -0,0 +1,44 @@ +function exist(board: string[][], word: string): boolean { + const m = board.length; + const n = board[0].length; + + const visited = Array.from({ length: m }, () => new Array(n).fill(0)); + function findDirection(currentI: number, currentJ: number, findNextIdx: number) { + if (findNextIdx === word.length) { + return true; + } + if ( + currentI < 0 || + currentJ < 0 || + currentI >= m || + currentJ >= n || + board[currentI][currentJ] !== word[findNextIdx] + ) { + return false; + } + if (visited[currentI][currentJ] === 1) { + return false; + } + visited[currentI][currentJ] = 1; + + const isApproachLastWord = + findDirection(currentI + 1, currentJ, findNextIdx + 1) || + findDirection(currentI - 1, currentJ, findNextIdx + 1) || + findDirection(currentI, currentJ - 1, findNextIdx + 1) || + findDirection(currentI, currentJ + 1, findNextIdx + 1); + + if (!isApproachLastWord) { + visited[currentI][currentJ] = 0; + } + return isApproachLastWord; + } + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + const result = findDirection(i, j, 0); + if (result) { + return true; + } + } + } + return false; +} From f486e1f0d57452cc9f48945529d7575e7163a64b Mon Sep 17 00:00:00 2001 From: casentino Date: Sun, 7 Dec 2025 03:11:32 +0900 Subject: [PATCH 5/5] Coin Change --- coin-change/casentino.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 coin-change/casentino.ts diff --git a/coin-change/casentino.ts b/coin-change/casentino.ts new file mode 100644 index 0000000000..bc800b6601 --- /dev/null +++ b/coin-change/casentino.ts @@ -0,0 +1,12 @@ +function coinChange(coins: number[], amount: number): number { + const dp = new Array(amount + 1).fill(amount); + dp[0] = 0; + for (let i = 1; i <= amount; i++) { + for (let j = 0; j < coins.length; j++) { + if (i - coins[j] >= 0) { + dp[i] = Math.min(dp[i - coins[j]] + 1, dp[i]); + } + } + } + return dp[amount] === Number.POSITIVE_INFINITY ? -1 : dp[amount]; +}