Skip to content

Commit 2d78170

Browse files
committed
Invert_Binary_tree/기초
1 parent 43f929c commit 2d78170

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var invertTree = function (root) {
2+
if (root === null) {
3+
return null;
4+
}
5+
6+
// 왼쪽과 오른쪽 자식 노드를 교환
7+
const temp = root.left;
8+
root.left = root.right;
9+
root.right = temp;
10+
11+
// 재귀적으로 자식 노드들을 반전
12+
invertTree(root.left);
13+
invertTree(root.right);
14+
15+
return root;
16+
};

0 commit comments

Comments
 (0)