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 a5b768d commit 4f1d3a8Copy full SHA for 4f1d3a8
invert-binary-tree/hwanmini.js
@@ -0,0 +1,30 @@
1
+// 시간복잡도: O(n)
2
+// 공간복잡도: O(n)
3
+
4
+/**
5
+ * Definition for a binary tree node.
6
+ * function TreeNode(val, left, right) {
7
+ * this.val = (val===undefined ? 0 : val)
8
+ * this.left = (left===undefined ? null : left)
9
+ * this.right = (right===undefined ? null : right)
10
+ * }
11
+ */
12
13
+ * @param {TreeNode} root
14
+ * @return {TreeNode}
15
16
+var invertTree = function(root) {
17
+ if (!root) return null;
18
19
+ const left = root.left
20
+ const right = root.right
21
22
+ root.left = right
23
+ root.right = left
24
25
26
+ invertTree(left)
27
+ invertTree(right)
28
29
+ return root
30
+};
0 commit comments