My C++ recursive solution


  • 0
    T
    TreeNode* invertTree(TreeNode* root) {
        if (root == nullptr)
            return nullptr;
        
        invertTree(root->left);
        invertTree(root->right);
        
        std::swap(root->left, root->right);
        
        return root;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.