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 fab1558 commit e817bb8Copy full SHA for e817bb8
Invert Binary Tree.js
@@ -0,0 +1,34 @@
1
+/*Invert a binary tree.
2
+ 4
3
+ / \
4
+ 2 7
5
+ / \ / \
6
+1 3 6 9
7
+to
8
9
10
+ 7 2
11
12
+9 6 3 1*/
13
+
14
+/**
15
+ * Definition for a binary tree node.
16
+ * function TreeNode(val) {
17
+ * this.val = val;
18
+ * this.left = this.right = null;
19
+ * }
20
+ */
21
22
+ * @param {TreeNode} root
23
+ * @return {TreeNode}
24
25
+var invertTree = function(root) {
26
+ if(root == null)
27
+ return null
28
+ temp = root.right
29
+ root.right = root.left
30
+ root.left = temp
31
+ invertTree(root.left)
32
+ invertTree(root.right)
33
+ return root
34
+};
0 commit comments