My code run correctly on local machine but produce [] (empty) array for every set of input on OJ. Can anyone help?


  • 0
    K

    int* productExceptSelf(int *a,int n,int *ret)
    {

    int *output,*b,*c,i,p1=1,p2=1;
    b=(int*)malloc(n*sizeof(int));
    c=(int*)malloc(n*sizeof(int));
    output=(int*)malloc(n*sizeof(int));
    for(i=0;i<n;i++)
    {
        p1=p1*a[i];
        p2=p2*a[n-i-1];
        b[i]=p1;
        c[n-i-1]=p2;
    }
    for(i=0;i<n;i++)
    {
        if(i==0)
        output[i]=c[i+1];
        else if(i==n-1)
        output[i]=b[i-1];
        else
        output[i]=b[i-1]*c[i+1];
    } return output;
    

    }


Log in to reply
 

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