File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ return root ;
33
+ } ;
You canโt perform that action at this time.
0 commit comments