题目链接:
https://leetcode.cn/problems/er-cha-shu-de-jing-xiang-lcof/description/?favorite=xb9nqhhg
题目:

代码:
class Solution {
public:
TreeNode* mirrorTree(TreeNode* root) {
TreeNode *ans;
if(root==NULL) return root;
TreeNode *tmp ;
tmp=root->left;
root->left=mirrorTree(root->right);
root->right=mirrorTree(tmp);
return root;
}
};
该问题涉及二叉树的翻转操作,通过递归方式实现。代码中定义了一个函数`mirrorTree`,它接收一个二叉树的根节点作为输入,首先检查根节点是否为空,然后交换左右子树,再对左右子树分别进行镜像处理,最终返回翻转后的根节点。
328

被折叠的 条评论
为什么被折叠?



