Skip to content

Commit 36285d8

Browse files
committed
pushing invert binary tree -- js solution
1 parent aa5995d commit 36285d8

File tree

1 file changed

+19
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)