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 3ac0528 commit 01ae490Copy full SHA for 01ae490
invert-binary-tree/wogha95.js
@@ -0,0 +1,33 @@
1
+/**
2
+ * 양쪽 자식 노드 주소를 교환하고 dfs로 순회합니다.
3
+ *
4
+ * TC: O(N)
5
+ * 모든 트리를 순회합니다.
6
7
+ * SC: O(N)
8
+ * 최악의 경우 (한쪽으로 치우친 트리) N만큼 CallStack이 생깁니다.
9
10
+ * N: tree의 모든 node 수
11
+ */
12
+
13
14
+ * Definition for a binary tree node.
15
+ * function TreeNode(val, left, right) {
16
+ * this.val = (val===undefined ? 0 : val)
17
+ * this.left = (left===undefined ? null : left)
18
+ * this.right = (right===undefined ? null : right)
19
+ * }
20
21
22
+ * @param {TreeNode} root
23
+ * @return {TreeNode}
24
25
+var invertTree = function (root) {
26
+ if (!root) {
27
+ return root;
28
+ }
29
+ [root.left, root.right] = [root.right, root.left];
30
+ invertTree(root.left);
31
+ invertTree(root.right);
32
33
+};
0 commit comments