From 5f6997b9b432f5eb6cd96be4d0f15d86aaf5acc4 Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Sat, 9 Aug 2025 11:26:51 +0900 Subject: [PATCH 1/4] combination-sum --- combination-sum/sooooo-an.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 combination-sum/sooooo-an.ts diff --git a/combination-sum/sooooo-an.ts b/combination-sum/sooooo-an.ts new file mode 100644 index 000000000..2e552d15e --- /dev/null +++ b/combination-sum/sooooo-an.ts @@ -0,0 +1,23 @@ +function combinationSum(candidates: number[], target: number): number[][] { + const result: number[][] = []; + + const dfs = (start: number, path: number[], sum: number) => { + if (sum === target) { + result.push([...path]); + return; + } + + if (sum > target) { + return; + } + + for (let i = start; i < candidates.length; i++) { + path.push(candidates[i]); + dfs(i, path, sum + candidates[i]); + path.pop(); + } + }; + + dfs(0, [], 0); + return result; +} From db3402319acbdb645df76734e11e412a2525d20b Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Fri, 15 Aug 2025 10:29:12 +0900 Subject: [PATCH 2/4] merge-two-sorted-lists --- merge-two-sorted-lists/sooooo-an.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 merge-two-sorted-lists/sooooo-an.ts diff --git a/merge-two-sorted-lists/sooooo-an.ts b/merge-two-sorted-lists/sooooo-an.ts new file mode 100644 index 000000000..f84245582 --- /dev/null +++ b/merge-two-sorted-lists/sooooo-an.ts @@ -0,0 +1,22 @@ +function mergeTwoLists( + list1: ListNode | null, + list2: ListNode | null +): ListNode | null { + const result = new ListNode(); + let tail = result; + + 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 result.next; +} From fd56326d9797dca2ec394bc347f3ba68587ac369 Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Fri, 15 Aug 2025 10:42:34 +0900 Subject: [PATCH 3/4] maximum-depth-of-binary-tree --- maximum-depth-of-binary-tree/sooooo-an.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 maximum-depth-of-binary-tree/sooooo-an.ts diff --git a/maximum-depth-of-binary-tree/sooooo-an.ts b/maximum-depth-of-binary-tree/sooooo-an.ts new file mode 100644 index 000000000..3e8078a00 --- /dev/null +++ b/maximum-depth-of-binary-tree/sooooo-an.ts @@ -0,0 +1,6 @@ +function maxDepth(root: TreeNode | null): number { + if (!root) return 0; + const left = maxDepth(root.left); + const right = maxDepth(root.right); + return Math.max(left, right) + 1; +} From 5a69f491fd881fbe129c97d0587dd26799d6ad62 Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Fri, 15 Aug 2025 12:32:45 +0900 Subject: [PATCH 4/4] find-minimum-in-rotated-sorted-array --- find-minimum-in-rotated-sorted-array/sooooo-an.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/sooooo-an.ts diff --git a/find-minimum-in-rotated-sorted-array/sooooo-an.ts b/find-minimum-in-rotated-sorted-array/sooooo-an.ts new file mode 100644 index 000000000..16f93e1a4 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/sooooo-an.ts @@ -0,0 +1,15 @@ +function findMin(nums: number[]): number { + let left = 0, + right = nums.length - 1; + + while (left < right) { + const mid = left + Math.floor((right - left) / 2); + if (nums[mid] > nums[right]) { + left = mid + 1; + } else { + right = mid; + } + } + + return nums[left]; +}