mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 23:09:36 +03:00
13 lines
316 B
C
13 lines
316 B
C
int cmpval(const void *a, const void *b) { return *(int *)a - *(int *)b; }
|
|
int findDuplicate(int *nums, int numsSize)
|
|
{
|
|
int i;
|
|
qsort(nums, numsSize, sizeof(int), cmpval);
|
|
for (i = 0; i < numsSize - 1; i++)
|
|
{
|
|
if (nums[i] == nums[i + 1])
|
|
return nums[i];
|
|
}
|
|
return nums[i];
|
|
}
|