Skip to content

Conversation

@dylan-jung
Copy link
Contributor

@dylan-jung dylan-jung commented Nov 18, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dylan-jung dylan-jung moved this from Solving to In Review in 리트코드 스터디 6기 Nov 21, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

안녕하세요! 전체적으로 코드가 깔끔해서 이해하기 쉬웠어요.
다만 이 코드에서는 추가적으로 null 노드에 대한 base case를 체크해 주면 더 좋을 것 같아요.

bool isValidBST(TreeNode* root) {
    if (!root) return true;
    return dfs(root, -(1L << 32), 1L << 32);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

또 한 가지는, dfs 함수의 맨 처음에서

if (!(minVal < root->val && root->val < maxVal)) return false;

이 조건을 이미 검사하고 있기 때문에, 이 시점에서는 항상
minVal < root->val < maxVal 가 보장됩니다.

그래서 min((long)root->val, maxVal)는 실제로는 항상 root->val과 같고,
마찬가지로 right 쪽에서도 max((long)root->val, minVal)는 항상 root->val과 같아서

if (root->left) {
    isValid = isValid && dfs(root->left, minVal, root->val);
}
if (root->right) {
    isValid = isValid && dfs(root->right, root->val, maxVal);
}

처럼 수정해도 동일하게 동작을 하게 되는거 같아요.

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. 제가 잘 안되는 부분 중 하나가 이렇게 엣지케이스 체킹하는 부분입니다. 놓친 부분 잘 체크해주셔서 감사합니다!

  2. 꼼꼼하게 살펴봐주셨네요 ㅎㅎㅎ 말씀해주신 부분이 맞습니다. 코드 고쳐서 푸시하겠습니다.

한 주 동안 고생 많으셨습니다!

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