-
-
Notifications
You must be signed in to change notification settings - Fork 195
[hsskey] Week 02 Solutions #1231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번주도 문제풀이하시느라 고생 많으셨습니다!
다음주도 화이팅입니다!
return false | ||
} | ||
|
||
return dfs(node.left, left, node.val) && dfs(node.right, node.val, right) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요! 좋은 주말입니다.
요 알고리즘 시간복잡도는 O(logN) 으로 생각이 되는데,
제 계산이 맞을까요??
아니라면 얼마나 되는지 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 @YoungSeok-Choi 님
해당 풀이는 O(logN)이 아닌 O(n) 풀이입니다.
이 문제를 일반적인 이진탐색인 O(logN)으로 보일 수 있으나, 이 문제는 탐색 구현이 아니라
문제의 요구사항은 트리 전체를 확인하는 검증과정이라고 볼 수 있습니다.
풀이 중 조건문을 통과한 코드들은 마지막 return문에서 재귀적으로 동작하게되는데,
이를 시각화해서 보면 왼쪽과 오른쪽으로 코드가 마치 배열을 선형적으로 순회하듯이 거치는것을 확인할 수 있습니다.
따라서 해당 풀이는 O(n)풀이가 됩니다.
...
...
return dfs(node.left, left, node.val) && dfs(node.right, node.val, right)
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!