Why is Run time error in my code ?


  • 0
    N
    struct TreeNode* preIn(int pre[],int in[],int inst,int ine)
    { static int prei=0;
    if(inst>ine) return NULL;
    struct TreeNode* rt = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    rt->val = pre[prei++];
    rt->left = NULL;
    rt->right = NULL;
    if(inst == ine) return rt;
    int i,ini;
    for(i=inst;i<=ine;i++)
        if(in[i]==rt->val) break;
    ini = i;
    rt->left = preIn(pre,in,inst,ini-1);
    rt->right = preIn(pre,in,ini+1,ine);
    return rt;
    };
    
    struct TreeNode* buildTree(int* preorder, int preorderSize, int* inorder, int inorderSize) 
    {  
        if(preorderSize<=0) return NULL;
    struct TreeNode* rt = preIn(preorder,inorder,0,preorderSize-1);
    return rt;
    }
    

    why is this code showing runtime error? But it runs fine on my pc..!! .Thanks for helping.


  • 0
    R

    my question is the same with you


  • 0
    K

    Facing same issue with same( i had written it before seeing this, my code is pretty much the same) code


Log in to reply
 

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