-
Notifications
You must be signed in to change notification settings - Fork 2
[동기] 20221212 백준 - 이가 빠진 이진 트리 풀이중 #657
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
Open
donggi-lee-bit
wants to merge
1
commit into
main
Choose a base branch
from
donggi-lee-bit-patch-26
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class Solution { | ||
|
|
||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
|
||
| int n = Integer.parseInt(br.readLine()); | ||
| int[] arr = new int[n]; | ||
| StringTokenizer st = new StringTokenizer(br.readLine(), " "); | ||
| for (int i = 0; i < n; i++) { | ||
| arr[i] = Integer.parseInt(st.nextToken()); | ||
| } | ||
|
|
||
| int x = Integer.parseInt(br.readLine()); | ||
| Solution s = new Solution(); | ||
| System.out.println(s.solution(n, arr, x)); | ||
| } | ||
|
|
||
| public String solution(int n, int[] arr, int x) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| // 모든 내부 노드가 두개의 자식 노드를 가지며, 모든 잎 노드가 동일한 깊이를 가진 이진트리 | ||
| // 모든 내부 노드가 두 개의 자식 노드를 가지고 있는지 체크 (어떻게? 일일히 모든 노드의 자식 노드를 확인?) | ||
| // -1, 가려진 하나의 노드 대신 x 값을 넣어 다시 포화 이진 트리를 그린다.. . 어떻게..? | ||
| // 후위 순회(왼쪽, 오른쪽, root) 결과를 출력 | ||
|
|
||
| return sb.toString(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class Node { | ||
| int value; | ||
| Node left; | ||
| Node right; | ||
|
|
||
|
|
||
| public Node(int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public Node(int value, Node left, Node right) { | ||
| this.value = value; | ||
| this.left = left; | ||
| this.right = right; | ||
| } | ||
|
|
||
| public void insert(int value) { | ||
| if (value < this.value) { | ||
| if (this.left == null) { | ||
| this.left = new Node(value); | ||
| } else { | ||
| this.left.insert(value); | ||
| } | ||
| } else { | ||
| if (this.right == null) { | ||
| this.right = new Node(value); | ||
| } else { | ||
| this.right.insert(value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
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.
저도 이런식으로 나름대로의 문제 해결 과정을 메모하거나 누군가한테 설명하는게 문제 해결에 도움되는 편인 것 같습니다 ㅎㅎ 👍👍
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.
어떻게? 밖에 없지만.. 조은 말씀 감사합니다 익조!! 👊