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 8df62a4 commit 9c3e0e5Copy full SHA for 9c3e0e5
invert-binary-tree/nhistory.js
@@ -0,0 +1,26 @@
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
+var invertTree = function (root) {
14
+ // Check root is null
15
+ if (!root) return null;
16
+ // Create left and right variable to make recurrsive
17
+ let left = root.left;
18
+ let right = root.right;
19
+ // Execute invertTree functino
20
+ root.left = invertTree(right);
21
+ root.right = invertTree(left);
22
+ return root;
23
+};
24
+
25
+// TC: O(n)
26
+// SC: O(n)
0 commit comments