forked from onlybooks/java-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP50_2.java
More file actions
19 lines (16 loc) · 511 Bytes
/
P50_2.java
File metadata and controls
19 lines (16 loc) · 511 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package ch14;
import datatype.TreeNode;
public class P50_2 {
public TreeNode invertTree(TreeNode root) {
// 빈 노드가 아닐때 처리
if (root != null) {
// 왼쪽/오른쪽 자식 노드 스왑
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
invertTree(root.left); // 왼쪽 자식 노드 DFS
invertTree(root.right); // 오른쪽 자식 노드 DFS
}
return root;
}
}