题目描述
输入一个二叉树,使其变成镜像树。
分析:
前段时间Max Howell面试google闹得风风火火的遗一题,没什么好说的,就是交换左右子树,递归解决。
代码:
void Mirror(TreeNode *pRoot) {
if(pRoot == nullptr) return;
TreeNode *temp = pRoot->right;
pRoot->right = pRoot->left;
pRoot->left = temp;
Mirror(pRoot->left);
Mirror(pRoot->right);
}