public static void main(String[] args) {
// TODO Auto-generated method stub
TreeNode root = new TreeNode(1);
root.left = new TreeNode(2);
root.left.left = new TreeNode(3);
root.right = new TreeNode(4);
root.right.left = new TreeNode(5);
root.right.right = new TreeNode(6);
root.right.right.left = new TreeNode(7);
mirror(root);
}
public static TreeNode mirror(TreeNode root){
if(root == null){
return null;
}
TreeNode left = mirror(root.left);
TreeNode right = mirror(root.right);
root.left = right;
root.right = left;
return root;
}
}
代码二
public class Solution {
public void Mirror(TreeNode root) {
TreeNode tmp = null;
if (root != null)
{
tmp = root.left;
root.left = root.right;
root.right = tmp;
if (root.left != null)
Mirror(root.left);
if (root.right != null)
Mirror(root.right);
}
}
}