【leetcode】找到所有数组中消失的数字

 

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */

int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize){

    int* hash = (int*)calloc(numsSize+1,sizeof(int));

    int i,pst=0;
    for(i=0; i<numsSize; i++)
        hash[nums[i]]++;
    
    for(i=1; i<=numsSize; i++){
        if(!hash[i])
            nums[pst++]=i;
    }

    *returnSize=pst;
    return nums;
}

 

posted @ 2020-10-17 01:07  温暖了寂寞  阅读(99)  评论(0编辑  收藏  举报