Skip to content

Conversation

@hyer0705
Copy link
Contributor

@hyer0705 hyer0705 commented Oct 28, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@hyer0705 hyer0705 moved this from Solving to In Review in 리트코드 스터디 5기 Oct 29, 2025
@rivkode rivkode self-requested a review October 30, 2025 14:17
Copy link
Member

@rivkode rivkode left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!

Comment on lines +20 to +26
const isSameTree = (root: TreeNode | null, subRoot: TreeNode | null): boolean => {
if (!root && !subRoot) return true;
if (!root || !subRoot) return false;
if (root.val !== subRoot.val) return false;

return isSameTree(root.left, subRoot.left) && isSameTree(root.right, subRoot.right);
};
Copy link
Member

Choose a reason for hiding this comment

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

isSameTree 구현을 정석대로 잘 구현해주신 것 같습니다 ! ts 에서는 !root 가 Null 여부를 판단해주는 것 같아서 또 배워갑니다 ㅎㅎ
마지막에 subRoot 그 자체로 포함하는지, 그리고 left, right 한번씩 넣어주어 자식들을 재귀형식으로 탐색하는 방법으로 잘 구현해주신 것 같습니다

Comment on lines +57 to +58
root.left = build(preStart + 1, preStart + leftSize, inStart, rootIdx - 1);
root.right = build(preStart + leftSize + 1, preEnd, rootIdx + 1, inEnd);
Copy link
Member

Choose a reason for hiding this comment

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

이 부분에서 어떤 기준으로 +1 을 하고 -1 을 하셨는지 여쭤봐도 될까요 ? 문제를 읽기만 하고 풀지는 못해서 여쭤봅니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1, -1을 하는 이유는 인덱스 범위를 조정하기 위함입니다.

먼저 기본 개념부터:

  • preorder[0]은 항상 현재 구간의 루트 노드
  • inorder에서 루트의 위치(rootIdx)를 찾으면,
    왼쪽은 왼쪽 서브트리, 오른쪽은 오른쪽 서브트리

예시: preorder = [4, 11, 56, 78], inorder = [11, 4, 56, 78]

  • root = 4 (preorder[0])
  • rootIdx = 1 (inorder에서 4의 위치)
  • 왼쪽 서브트리 크기(leftSize) = 1 (rootIdx - inStart = 1 - 0)

왼쪽 서브트리의 범위:
preorder: [11] → 인덱스 [1, 1]
inorder: [11] → 인덱스 [0, 0]

root.left = build(preStart + 1, preStart + leftSize, inStart, rootIdx - 1)

  • preStart + 1: 루트(preorder[0])를 건너뛰고 그 다음부터 시작
  • preStart + leftSize: 왼쪽 서브트리 크기만큼만 포함 (1 + 1 = 2, 하지만 범위는 [1,1])
  • inStart: 왼쪽 서브트리는 inorder의 시작점부터 시작하므로 그대로
  • rootIdx - 1: 루트 직전까지가 왼쪽 서브트리의 끝

오른쪽 서브트리도 같은 논리로:

  • preStart + leftSize + 1: 루트 + 왼쪽 서브트리를 건너뛴 다음부터
  • rootIdx + 1: 루트 다음부터가 오른쪽 서브트리의 시작

Comment on lines +15 to +19
const [s1, e1] = expandAroundCenter(s, i, i);
const [s2, e2] = expandAroundCenter(s, i, i + 1);

const odd = e1 - s1 + 1;
const even = e2 - s2 + 1;
Copy link
Member

Choose a reason for hiding this comment

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

위의 expandAroundCenter 함수의 while 부분에서는 left 와 right 로 포인터를 잡아서 서로 길이가 같을때까지 루프를 도는 것 까지는 이해를 하였는데
여기 For 문에서의 s, i, i 와 s, i, i+1 을 사용하신 부분은 어떤 의도로 사용하신지가 궁금합니다 ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Palindrome이 홀수 길이일 경우, 짝수 길이일 경우에 대해서 체크하는 코드입니다.
예시) "토마토", "라랄랄라"

홀수의 경우는 left, right 포인터가 동일하면 되지만 짝수의 경우는 가운데가 두 개여야 하므로 s, i, i+1을 사용했습니다!

expandAroundCenter() 함수는 넘겨준 파라미터인 left와 right에서 시작해서 각각 왼쪽 오른쪽 문자가 같은지 확인해서 펠린드롬을 확인합니다. left, right가 가운데로 설정하는걸 홀수일 때, 짝수일 때 확인해보기 위해서 s, i, i 를 넣어 호출(홀수) 하고 s, i, i+1을 넣어 호출(짝수)하였습니다.

@hyer0705 hyer0705 merged commit 2f5427e into DaleStudy:main Nov 1, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 5기 Nov 1, 2025
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