每日力扣-树-二叉树的镜像

72 阅读1分钟

解题思路:看了题解居然发现还有swap这个函数,牛嗷

class Solution {
public:
    TreeNode* mirrorTree(TreeNode* root) {
        if (root == NULL)   return NULL; 
        mirrorTree(root->left);
        mirrorTree(root->right);
        swap(root->left, root->right);
        return root;        
    }
};