Skip to content

Commit fff83de

Browse files
committed
이진 트리 반전 / 기초
1 parent 5da58e8 commit fff83de

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val, left, right) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.left = (left===undefined ? null : left)
6+
* this.right = (right===undefined ? null : right)
7+
* }
8+
*/
9+
/**
10+
* @param {TreeNode} root
11+
* @return {TreeNode}
12+
*/
13+
function invertTree(root) {
14+
if (!root) return null;
15+
16+
[root.left, root.right] = [invertTree(root.right), invertTree(root.left)];
17+
18+
return root;
19+
};
20+

0 commit comments

Comments
 (0)