From f5e19826ea98f6c3f132d457d195875da117e724 Mon Sep 17 00:00:00 2001 From: JIHOON LEE Date: Mon, 21 Apr 2025 10:57:43 +0900 Subject: [PATCH 1/4] solving Merge Two Sorted Lists (#224) - https://github.com/DaleStudy/leetcode-study/issues/224 --- merge-two-sorted-lists/jiji-hoon96.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 merge-two-sorted-lists/jiji-hoon96.ts diff --git a/merge-two-sorted-lists/jiji-hoon96.ts b/merge-two-sorted-lists/jiji-hoon96.ts new file mode 100644 index 000000000..95effd54d --- /dev/null +++ b/merge-two-sorted-lists/jiji-hoon96.ts @@ -0,0 +1,15 @@ +/** + * 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 { + +}; \ No newline at end of file From e706586fbba15e3943a17c3f9cb521f056cf6e17 Mon Sep 17 00:00:00 2001 From: JIHOON LEE Date: Sat, 26 Apr 2025 09:59:15 +0900 Subject: [PATCH 2/4] solution Merge Two Sorted Lists (#224) - https://github.com/DaleStudy/leetcode-study/issues/224 --- merge-two-sorted-lists/jiji-hoon96.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/merge-two-sorted-lists/jiji-hoon96.ts b/merge-two-sorted-lists/jiji-hoon96.ts index 95effd54d..c0b375f9b 100644 --- a/merge-two-sorted-lists/jiji-hoon96.ts +++ b/merge-two-sorted-lists/jiji-hoon96.ts @@ -11,5 +11,25 @@ */ function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode | null { - -}; \ No newline at end of file + // 더미 헤드 노드를 생성하여 결과 리스트의 시작점으로 사용 + const dummy = new ListNode(0); + let current = dummy; + + // 두 리스트를 순회하면서 더 작은 값을 가진 노드를 결과 리스트에 연결 + while (list1 !== null && list2 !== null) { + if (list1.val <= list2.val) { + current.next = list1; + list1 = list1.next; + } else { + current.next = list2; + list2 = list2.next; + } + current = current.next; + } + + // 남은 노드들을 결과 리스트에 연결 + current.next = list1 === null ? list2 : list1; + + // 더미 노드의 다음 노드가 실제 병합된 리스트의 헤드 + return dummy.next; +} From 8ea2c0dacb54f2e83aceeed160ec61915d635b09 Mon Sep 17 00:00:00 2001 From: JIHOON LEE Date: Sat, 26 Apr 2025 10:02:22 +0900 Subject: [PATCH 3/4] solution Maximum Depth of Binary Tree (#227) - https://github.com/DaleStudy/leetcode-study/issues/227 --- maximum-depth-of-binary-tree/jiji-hoon96.ts | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 maximum-depth-of-binary-tree/jiji-hoon96.ts diff --git a/maximum-depth-of-binary-tree/jiji-hoon96.ts b/maximum-depth-of-binary-tree/jiji-hoon96.ts new file mode 100644 index 000000000..32204e567 --- /dev/null +++ b/maximum-depth-of-binary-tree/jiji-hoon96.ts @@ -0,0 +1,29 @@ +/** + * 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 { + // 기본 케이스: 노드가 없는 경우 깊이는 0 + if (root === null) { + return 0; + } + + // 왼쪽 서브트리의 최대 깊이 + const leftDepth = maxDepth(root.left); + + // 오른쪽 서브트리의 최대 깊이 + const rightDepth = maxDepth(root.right); + + // 현재 노드의 깊이는 왼쪽과 오른쪽 서브트리 중 더 깊은 것에 1을 더한 값 + return Math.max(leftDepth, rightDepth) + 1; +} \ No newline at end of file From 3e7e4f2503ca06d5dd40f821de0daea2c86c70de Mon Sep 17 00:00:00 2001 From: JIHOON LEE Date: Sat, 26 Apr 2025 10:02:34 +0900 Subject: [PATCH 4/4] solution Maximum Depth of Binary Tree (#227) - https://github.com/DaleStudy/leetcode-study/issues/227 --- maximum-depth-of-binary-tree/jiji-hoon96.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maximum-depth-of-binary-tree/jiji-hoon96.ts b/maximum-depth-of-binary-tree/jiji-hoon96.ts index 32204e567..343a1f5c4 100644 --- a/maximum-depth-of-binary-tree/jiji-hoon96.ts +++ b/maximum-depth-of-binary-tree/jiji-hoon96.ts @@ -26,4 +26,4 @@ function maxDepth(root: TreeNode | null): number { // 현재 노드의 깊이는 왼쪽과 오른쪽 서브트리 중 더 깊은 것에 1을 더한 값 return Math.max(leftDepth, rightDepth) + 1; -} \ No newline at end of file +}