Skip to content

Commit c8f5e8d

Browse files
authored
Add files via upload
1 parent c5455a0 commit c8f5e8d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

InvertBinaryTree.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//https://leetcode.com/problems/invert-binary-tree/submissions/
2+
public class InvertBinaryTree {
3+
4+
public TreeNode invertTree(TreeNode root) {
5+
TreeNode head=root;
6+
if(root!=null){
7+
inverse(root);
8+
}
9+
return head;
10+
}
11+
12+
public void inverse(TreeNode root) {
13+
if(root!=null) {
14+
TreeNode t=root.left;
15+
root.left=root.right;
16+
root.right=t;
17+
inverse(root.left);
18+
inverse(root.right);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)