dfs递归遍历二叉树,从底向上依次交换各个节点的左右子节点,生成镜像二叉树

public class Solution {

public TreeNode Mirror (TreeNode pRoot) {
    // write code here
    if(pRoot==null || (pRoot.left==null&&pRoot.right==null))
        return pRoot;
    TreeNode left = Mirror(pRoot.left);
    TreeNode right = Mirror(pRoot.right);
    pRoot.right = left;
    pRoot.left = right;
    return pRoot;
}

}