using hash table by C


  • 0
    M
    int missingNumber(int* nums, int numsSize) {
        int* hash = (int *)malloc(sizeof(int)*(numsSize+1));
        for (int i = 0; i < numsSize+1; i++) hash[i] = 0;
        
        for (int i = 0; i < numsSize; i++) hash[nums[i]] = 1;
        int i = 0;
        for (; i < numsSize+1; i++) if (hash[i] == 0) break;
        
        return i;
    }
    

Log in to reply
 

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