Skip to content

Commit 4f1d3a8

Browse files
committed
feat: 문제풀이 추가
1 parent a5b768d commit 4f1d3a8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

invert-binary-tree/hwanmini.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)