练习:二叉树的镜像

练习:二叉树的镜像

1、题目要求

操作给定的二叉树,将其变换为源二叉树的镜像。

2、我的代码

/*
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};*/
class Solution {
public:
    void Mirror(TreeNode *pRoot) {
        if(pRoot == NULL) return;
        swap(pRoot->left, pRoot->right);
        if(pRoot->left) Mirror(pRoot->left);
        if(pRoot->right) Mirror(pRoot->right);
    }
};

猜你喜欢

转载自blog.csdn.net/houzijushi/article/details/81138310