思路:递归将树的左右节点交换
代码:
/**
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public void Mirror(TreeNode root) {
mirror(root);
}
static void mirror(TreeNode root){
if(root == null){
return;
}
TreeNode temp = root.right;
root.right = root.left;
root.left = temp;
mirror(root.right);
mirror(root.left);
}
}
end