【leetcode】数组中重复的数字

 

int findRepeatNumber(int* nums, int numsSize){
    int max = nums[0];
    for (int j = 1; j<numsSize; j++)
    {
        if (nums[j] > max)
            max = nums[j];
    }
    int *hash = (int *)calloc(max+1, sizeof(int));
    for(int i = 0; i < numsSize; i++){
        if(hash[nums[i]] == 1){
            return nums[i];
        } else {
            hash[nums[i]]++;
        }
    }
    return -1;
}

 

posted @ 2020-08-20 13:29  温暖了寂寞  阅读(198)  评论(0编辑  收藏  举报