[20251007] PGM / Lv3 / 표현 가능한 이진 트리 / 이강현 #1059
Merged
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.
🧷 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/150367
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
이진트리가 하나 존재한다고 가정하자.
이때 빈 노드로 이진 트리를 포화상태로 만들고 기존노드는 1, 추가된 빈 노드는 0이라고 생각한다.
트리의 높이와는 상관없이 왼쪽부터 노드를 읽었을때, 이진수의 꼴로 나타나질 것이다.
숫자가 주어질때, 위와 같은 방법으로 나타나질 수 있는 수라면 1 아니라면 0을 출력한다.
🔍 풀이 방법
재귀, 트리
숫자를 이진수의 형태로 변환한 후, 포화 이진트리의 노드 수만큼 패딩함.
그리고 루트에 접근하여 왼쪽, 오른쪽 서브트리에 대해서 검사함.
루트가 0이라면 그 아래 자식들또한 모두 0이어야 함.
그렇지 않다면 존재할 수 없으므로 0을 출력.
모두 통과한다면 표현 가능하므로 1을 출력.
⏳ 회고
카카오 문제는 결국 풀면 그렇게 어려운 알고리즘이 사용되지 않는데, 구현하기가 왜캐 어려운지 모르겟다.