题目描述
操作给定的二叉树,将其变换为源二叉树的镜像。
<?php
/*class TreeNode{
var $val;
var $left = NULL;
var $right = NULL;
function __construct($val){
$this->val = $val;
}
}*/
function Mirror(&$root)
{
// write code here
$tree=new TreeNode(null);
if($root!=null){
$tree=$root->right;
$root->right=$root->left;
$root->left=$tree;
if($root->left!=null){
Mirror($root->left);
}
if($root->right!=null){
Mirror($root->right);
}
}
return $root;
}