题目19:二叉树的镜像(leetcode链接:https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/)
题目分析
代码描述
class Solution {
public:
TreeNode* mirrorTree(TreeNode* root) {
if(root == NULL || (root->left == NULL && root->right == NULL))
return root;
//交换左右子树的跟节点
TreeNode* tmp = root->left;
root->left = mirrorTree(root->right);
root->right = mirrorTree(tmp);
return root;
}
};