C solution with using hashmap


  • 0
    N

    int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize) {
    int tag = (int)malloc(sizeof(int)*numsSize);
    for(int i = 0;i<numsSize;i++){
    tag[i] = 0;
    }
    for(int i = 0;i< numsSize; i++){
    int idx = (nums[i] -1) % numsSize;
    tag[idx]++;
    }
    int count = 0;
    for(int i = 0;i < numsSize; i++){
    if(tag[i] == 0){
    count++;
    }
    }
    int no_nums = (int)malloc(sizeof(int)*count);
    *returnSize = count;
    count = 0;
    for(int i = 0;i < numsSize; i++){
    if(tag[i] == 0){
    no_nums[count] = i + 1;
    count++;
    }
    }
    return no_nums;
    }


Log in to reply
 

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