Sharing my simple recursive solution (0 ms)


  • 0
    C
    class Solution {
    

    public:
    TreeNode* invertTree(TreeNode* root) {

        if(root == NULL)
        return NULL;
        
        struct TreeNode *temp;
        
        temp = root->left;
        root->left = root->right;
        root->right = temp;
        
        invertTree(root->left);
        invertTree(root->right);
        
        return root;
    }
    

    };


  • 0
    A
    This post is deleted!

Log in to reply
 

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