剑指offer(18) 二叉树的镜像

题目描述
*操作给定的二叉树,将其变换为源二叉树的镜像。
输入描述:
二叉树的镜像定义:源二叉树 *
在这里插入图片描述
解题思路
是一个递归的思路,二叉树可以转换为最小的子树结构,然后对最小的子树进行镜像即可。

class Solution {
public:
    void Mirror(TreeNode *pRoot) {
        if(pRoot==NULL){
            return;
        }
        TreeNode *tmp = pRoot->left;
        pRoot->left = pRoot->right;
        pRoot->right = tmp;
        Mirror(pRoot->left);
        Mirror(pRoot->right);
    }
};

猜你喜欢

转载自blog.csdn.net/weixin_43624053/article/details/85019922