Skip to content

Commit 6ddb818

Browse files
committed
invert binary tree solution
1 parent 9716591 commit 6ddb818

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

invert-binary-tree/byol-han.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* https://leetcode.com/problems/invert-binary-tree/submissions/1651537941/
3+
* Definition for a binary tree node.
4+
* function TreeNode(val, left, right) {
5+
* this.val = (val===undefined ? 0 : val)
6+
* this.left = (left===undefined ? null : left)
7+
* this.right = (right===undefined ? null : right)
8+
* }
9+
*/
10+
/**
11+
* @param {TreeNode} root
12+
* @return {TreeNode}
13+
*/
14+
var invertTree = function (root) {
15+
if (root === null) return null;
16+
17+
// 왼쪽과 오른쪽 자식 노드 바꾸기
18+
[root.left, root.right] = [invertTree(root.right), invertTree(root.left)];
19+
20+
return root;
21+
};

0 commit comments

Comments
 (0)