Merged
Conversation
YoungSeok-Choi
approved these changes
Apr 12, 2025
Contributor
YoungSeok-Choi
left a comment
There was a problem hiding this comment.
이번주도 문제풀이하시느라 고생 많으셨습니다!
다음주도 화이팅입니다!
| return false | ||
| } | ||
|
|
||
| return dfs(node.left, left, node.val) && dfs(node.right, node.val, right) |
Contributor
There was a problem hiding this comment.
안녕하세요! 좋은 주말입니다.
요 알고리즘 시간복잡도는 O(logN) 으로 생각이 되는데,
제 계산이 맞을까요??
아니라면 얼마나 되는지 궁금합니다!
Member
Author
There was a problem hiding this comment.
안녕하세요 @YoungSeok-Choi 님
해당 풀이는 O(logN)이 아닌 O(n) 풀이입니다.
이 문제를 일반적인 이진탐색인 O(logN)으로 보일 수 있으나, 이 문제는 탐색 구현이 아니라
문제의 요구사항은 트리 전체를 확인하는 검증과정이라고 볼 수 있습니다.
풀이 중 조건문을 통과한 코드들은 마지막 return문에서 재귀적으로 동작하게되는데,
이를 시각화해서 보면 왼쪽과 오른쪽으로 코드가 마치 배열을 선형적으로 순회하듯이 거치는것을 확인할 수 있습니다.
따라서 해당 풀이는 O(n)풀이가 됩니다.
...
...
return dfs(node.left, left, node.val) && dfs(node.right, node.val, right)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!