Is leetcode online jugde weird ? [C]


  • 0
    T

    Here is my code and try to test the follow two case.

    int* nextGreaterElement(int* findNums, int findNumsSize, int* nums, int numsSize, int* returnSize) {
        int i,j,maxNums = -99999,minNums = 99999;
        int tmp;
        *returnSize = findNumsSize;
        int* ans = (int*)malloc(sizeof(int)*findNumsSize);
        
        for(i=0;i<numsSize;i++){
        	maxNums = (nums[i] > maxNums ? nums[i]:maxNums);
        	minNums = (nums[i] < minNums ? nums[i]:minNums);
        }
            	
        int *hashTable = (int*)malloc((maxNums - minNums)*sizeof(int));
        for(i=0;i<numsSize;i++){
        	for(j=i+1;j<numsSize;j++){
        		if(nums[j]>nums[i])
        			break;
        	}
    
        	hashTable[nums[i] - minNums] = ((j==numsSize) ? -1:nums[j]);
        	
        }
        for(i=0;i<findNumsSize;i++){
        	ans[i] = hashTable[findNums[i] - minNums];       
        }
        free(hashTable);
        return ans;
    }
    

    case 1:
    [3,1,5,7,9,2,6]
    [1,2,3,5,6,7,9,11]
    case 2:
    [3,1,5,7,9,2,6]
    [1,2,3,5,6,7,9,12]

    why case 1 get the error message but it work for case 2 ?

    free(): invalid next size (fast): 0x00007f18100009f0 ***
    

Log in to reply
 

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