We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5da58e8 commit fff83deCopy full SHA for fff83de
JooKangSan/[week5]Tree/Invert_Binary_Tree.js
@@ -0,0 +1,20 @@
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
+function invertTree(root) {
14
+ if (!root) return null;
15
+
16
+ [root.left, root.right] = [invertTree(root.right), invertTree(root.left)];
17
18
+ return root;
19
+ };
20
0 commit comments