剑指offer---二叉树的镜像
作者:互联网
题目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;
}
};
标签:right,TreeNode,offer,---,二叉树,left,NULL,root,mirrorTree 来源: https://blog.csdn.net/qq_47406941/article/details/114452666