Skip to content

Conversation

@casentino
Copy link
Contributor

@casentino casentino commented Dec 3, 2025

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@github-actions github-actions bot added the ts label Dec 3, 2025
@casentino casentino changed the title Merge Two Sorted Lists [casentino] WEEK 04 Solutions Dec 3, 2025
Copy link
Contributor

@ys-han00 ys-han00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

날씨가 많이 추워진 한 주네요!

아직 모든 문제를 풀이 중이시지만, 먼저 풀어두신 문제들에 대해서 리뷰를 남겨두었습니다. 😊

제가 리뷰에 아직 익숙하지 않아 부족한 부분이 있을 수 있으니,

이상한 점이나 궁금한 점이 있으시면 언제든지 PR 멘션이나 Discord로 편하게 말씀해주세요!

남은 문제들도 화이팅하시고, 추운 날씨에 감기 조심하세요! ❄️💪

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보기 좋은 이분 탐색 코드네요 👍

Comment on lines +27 to +36
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;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석을 풀어 두신 이유가 있을까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타입스크립트 컴파일 에러 나길래 선언만 해두었어요!

Comment on lines +15 to +25
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알고리즘을 아래처럼 이해했는데, 맞게 이해했다면 좋은 로직이네요!

  1. Leaf Node의 자식은 NULL 값으로 더 갈 수 없으니 깊이 count를 반환한다.
  2. Node의 왼쪽(left), 오른쪽(right) 나누어 DFS를 진행하고 그 중 더 큰 값을 반환한다.

현재 함수는 count를 매개변수로 전달하면서 깊이를 추적하고 있는데요,
깊이를 인자로 들고 다니지 않고, 재귀의 반환 값 자체가 깊이가 되도록 만드는 방식도 한 번 고려해보시면 좋을 것 같습니다.

예를 들어 노드가 없을 때 0을 반환하고,
1 + max(leftDepth, rightDepth) 형태로 계산하면
각 재귀 호출이 자신의 서브트리 깊이를 자연스럽게 return 값으로 전달하게 됩니다.

이렇게 하면 재귀 함수의 매개변수를 줄일 수 있어요! 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러네요! 말씀해주신 방법으로도 풀어봐야겠어요! 조언 감사드려요 🙇‍♂️

Comment on lines +13 to +31
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

재귀로도 이렇게 깔끔한 풀이가 가능하네요! 😮

node1.val < node2.val 기준으로 next를 재귀적으로 이어붙이는 구조가 명확하게 보여서 로직이 한눈에 보이네요!!

저는 재귀가 약해서 이해하는 데 조금 시간이 걸렸는데요 😅

다음에는 참고해서 풀어봐야겠어요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 재귀는 아직 구현하면서도 햇갈려서 조건주는게 많이 어색한것같아요 ㅠ 더 많이 풀어봐야할것같아요!

Copy link
Contributor

@ys-han00 ys-han00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

금요일이다 보니 미리 승인해두겠습니다!

@casentino casentino moved this from Solving to Completed in 리트코드 스터디 6기 Dec 6, 2025
@casentino casentino merged commit 8ddeaea into DaleStudy:main Dec 6, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

2 participants