【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;
}
相关文章
相关标签/搜索