You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
375 B
22 lines
375 B
2 years ago
|
package class37;
|
||
|
|
||
|
public class Problem_0226_InvertBinaryTree {
|
||
|
|
||
|
public class TreeNode {
|
||
|
public int val;
|
||
|
public TreeNode left;
|
||
|
public TreeNode right;
|
||
|
}
|
||
|
|
||
|
public static TreeNode invertTree(TreeNode root) {
|
||
|
if (root == null) {
|
||
|
return null;
|
||
|
}
|
||
|
TreeNode left = root.left;
|
||
|
root.left = invertTree(root.right);
|
||
|
root.right = invertTree(left);
|
||
|
return root;
|
||
|
}
|
||
|
|
||
|
}
|