C solution using recursion


  • 0
    struct TreeNode* invertTree(struct TreeNode* root) {
        struct TreeNode* tmp;
        if(root == NULL)
            return root;
        else{
            tmp = invertTree(root->left);
            root->left = invertTree(root->right);
            root->right = tmp;
            return root;
        }
    }

Log in to reply
 

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