Skip to content

Commit 38c3322

Browse files
committed
invert binary tree solution
1 parent 356e622 commit 38c3322

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

invert-binary-tree/limlimjo.js

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

0 commit comments

Comments
 (0)