LillianEom
6/19/2018 - 1:02 PM

得到二叉树的镜像

前序遍历,交换左右结点,递归。

/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;
    }
}
*/
public class MirrorBinaryTree {
    public void Mirror(TreeNode root) {
        if(root == null) {
            return;
        } else {
            TreeNode temp = root.left;
            root.left = root.right;
            root.right = temp;
        }        
        Mirror(root.left);
        Mirror(root.right);
    }
}