【leetcode】错误的集合

 

int* findErrorNums(int* nums, int numsSize, int* returnSize){
    int* arr = (int*)malloc(2*sizeof(int));
    int* hash = (int*)calloc(numsSize,sizeof(int));    
    for (int i=0; i<numsSize; i++) hash[nums[i]-1]++;
    for (int j=0; j<numsSize; j++)
    {
        if(hash[j] == 0) arr[1] = j+1;
        else if (hash[j] == 2) arr[0] = j+1;
    }
    *returnSize = 2;
    return arr;
}

 

posted @ 2020-09-06 14:36  温暖了寂寞  阅读(115)  评论(0编辑  收藏  举报