Skip to content

Commit 04f7c0e

Browse files
committed
invert binary tree
1 parent f5f1c9c commit 04f7c0e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

invert-binary-tree/eunhwa99.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
3+
public TreeNode invertTree(TreeNode root) {
4+
if (root == null) {
5+
return null;
6+
}
7+
8+
TreeNode tmp = root.left;
9+
root.left = root.right;
10+
root.right = tmp;
11+
12+
invertTree(root.right);
13+
invertTree(root.left);
14+
15+
return root;
16+
}
17+
18+
}

0 commit comments

Comments
 (0)