Skip to content

Commit cd72027

Browse files
authored
InvertBinaryTree.js (codesONLY#76)
1 parent 4c8f680 commit cd72027

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

DSA/DFS/InvertBinaryTree.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
var invertTree = function(root) {
11+
if(!root) {
12+
return null;
13+
}
14+
[root.left, root.right] = [invertTree(root.right), invertTree(root.left)];
15+
return root;
16+
};

0 commit comments

Comments
 (0)