Difference between Run Code and Submit Solution ?


  • 0
    F

    When I press Run Code, the result for Input [2147483647] (Custom test case) is 2147483647

    But while I submit my solution, the results came out as follow....

    Input:
    [2147483647]
    Output:
    2048
    Expected:
    2147483647
    

    I just can't get it...
    Here's my C code for reference

    #include <stdint.h>
    
    #define MAX(X,Y)  ( ((X) > (Y)) ? (X) : (Y) )
    
    #define OK              1
    #define ALREADY_EXIST   2
    #define HASH_FULL       3
    
    // for used[]
    #define NOT_SAVED       0
    #define SAVED           1
    
    #define HASH_SIZE   6151
    int hashTable[HASH_SIZE];
    int used[HASH_SIZE];
    
    int getKey(int64_t value) { return (value+HASH_SIZE)%HASH_SIZE; }
    int modValue(int64_t value) { return (value+HASH_SIZE)%HASH_SIZE; }
    
    int put(int value)
    {
        int64_t i;
        int key = getKey(value);
        // loop until back to pos key-1
        for (i=key; i!=modValue(key-1); i=modValue(i+1) )
        {
            if (used[i]==NOT_SAVED) {
                hashTable[i] = value;
                ++used[i];
                return OK;
            }
            else if (hashTable[i]==value) {
                ++used[i];
                return ALREADY_EXIST;
            }
    
        }
        return HASH_FULL;
    }
    
    
    int majorityElement(int* nums, int numsSize) {
        int i;
    
        memset(used,NOT_SAVED,HASH_SIZE*sizeof(char));
    
        for (i=0;i<numsSize;i++) {
            put(nums[i]);
        }
    
        for (i=0;i<HASH_SIZE;i++) {
            if ( used[i] >= (numsSize+1)/2)
                return hashTable[i];
        }
    
        // error
        return 0;
    }
    

Log in to reply
 

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