Why runtime only beats 17.36% of csubmissions?


  • -1
    C

    struct TreeNode* invertTree(struct TreeNode* root) {
    if(root==NULL)
    {
    return;
    }
    if(root->left==NULL && root->right==NULL)
    {
    return root;
    }
    if(root->left==NULL)
    {
    root->left=invertTree(root->right);
    root->right=NULL;
    }
    else if(root->right==NULL)
    {
    root->right=invertTree(root->left);
    root->left=NULL;
    }
    else
    {
    struct TreeNode* l=root->right;
    root->right = root->left;
    root->left = l;
    invertTree(root->left);
    invertTree(root->right);
    }
    return root;
    }


Log in to reply
 

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