Skip to content

Commit 474e7c6

Browse files
authored
Create 226-invert-binary-tree.js
1 parent 27b66db commit 474e7c6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

226-invert-binary-tree.js

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

0 commit comments

Comments
 (0)