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 3ca602b commit ed96297Copy full SHA for ed96297
invert-binary-tree/uraflower.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
11
+ * 이진 트리를 좌우 반전하여 반환하는 함수
12
+ * @param {TreeNode} root
13
+ * @return {TreeNode}
14
15
+const invertTree = function (root) {
16
+ if (root !== null) {
17
+ invertTree(root.right);
18
+ invertTree(root.left);
19
+ [root.right, root.left] = [root.left, root.right];
20
+ }
21
22
+ return root;
23
+};
24
25
+// 시간복잡도: O(n)
26
+// 공간복잡도: O(n)
0 commit comments