Skip to content

Commit f5c94ae

Browse files
committed
containsDuplicate solution
1 parent d975b97 commit f5c94ae

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

contains-duplicate/sungjinwi.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdlib.h>
2+
#include <stdbool.h>
3+
4+
int compare(void const *a, void const *b)
5+
{
6+
return (*(int *)a - *(int *)b);
7+
}
8+
9+
bool containsDuplicate(int* nums, int numsSize) {\
10+
int i;
11+
12+
i = 0;
13+
qsort(nums, numsSize, sizeof(int), compare);
14+
while (i < numsSize - 1)
15+
{
16+
if (nums[i] == nums[i + 1])
17+
return (1);
18+
i++;
19+
}
20+
return (0);
21+
}

0 commit comments

Comments
 (0)