run wrong in submit , but right in test case ??


  • 0
    J

    My code run wrong [1,1] in submit , but right in test case .
    who can explain this ?

    the diff result

    alt text

    my code:

    /**
     * Return an array of size *returnSize.
     * Note: The returned array must be malloced, assume caller calls free().
     */
    int* findErrorNums(int* nums, int numsSize, int* returnSize) {
    
        int *cal, *re;
        cal = malloc(sizeof(int)*(numsSize+1));
        re  = malloc(sizeof(int)*(2));
        
        
        memset(cal,0,sizeof(cal)/sizeof(int));
        memset(re,0,sizeof(re)/sizeof(int));
        
        for(int i=0;i<numsSize;i++){
            ++cal[nums[i]];//=numsX[i];
        }
        
        
        for(int i=1; i<=numsSize;i++)
        {
            if(2==cal[i])
            {
                // printf("0: %d\n",i);
                *re=i;
            }
            else if(0==cal[i])
            {
                // printf("2: %d\n",i);
                *(re+1)=i;
            }
        }
        *returnSize = 2;
        
        if(*re==0 && *(re+1)==0 )
        {
            re=NULL;
            *returnSize = 0;
            
        }
        return re;
        
    }
    

Log in to reply
 

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