二叉树的镜像

输入一个二叉树,将它变换为它的镜像。

 
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    void mirror(TreeNode* root) {
        if (!root) return;
        mirror (root->left);
        mirror (root->right);
        swap (root->left, root->right);
    } 
};

  

posted @ 2022-12-14 22:46  !&&||  阅读(26)  评论(0)    收藏  举报