Skip to content

Commit 7e5b79b

Browse files
authored
Update 226-invert-binary-tree.js
1 parent b16c8f5 commit 7e5b79b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

226-invert-binary-tree.js

+22
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,25 @@ const invertTree = function (root) {
4848
}
4949
return root
5050
}
51+
52+
// anoother
53+
54+
/**
55+
* Definition for a binary tree node.
56+
* function TreeNode(val, left, right) {
57+
* this.val = (val===undefined ? 0 : val)
58+
* this.left = (left===undefined ? null : left)
59+
* this.right = (right===undefined ? null : right)
60+
* }
61+
*/
62+
/**
63+
* @param {TreeNode} root
64+
* @return {TreeNode}
65+
*/
66+
const invertTree = function(root) {
67+
if(root == null) return root
68+
let tmp = root.left
69+
root.left = invertTree(root.right)
70+
root.right = invertTree(tmp)
71+
return root
72+
};

0 commit comments

Comments
 (0)