Skip to content

Commit 50f5a62

Browse files
committed
feat: invert-binary-tree
1 parent 59706e8 commit 50f5a62

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

BinaryTree/invert-binary-tree.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function invertTree(root: TreeNode | null): TreeNode | null {
2+
if (!root) {
3+
return root;
4+
}
5+
let temp:(TreeNode | null);
6+
temp = root.left;
7+
root.left = root.right;
8+
root.right = temp;
9+
invertTree(root.left);
10+
invertTree(root.right);
11+
return root;
12+
};

0 commit comments

Comments
 (0)