Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions 동기/20221212.java
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) 결과를 출력
Copy link
Collaborator

Choose a reason for hiding this comment

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

저도 이런식으로 나름대로의 문제 해결 과정을 메모하거나 누군가한테 설명하는게 문제 해결에 도움되는 편인 것 같습니다 ㅎㅎ 👍👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

어떻게? 밖에 없지만.. 조은 말씀 감사합니다 익조!! 👊


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);
}
}
}
}