Skip to content

Commit 2750e33

Browse files
author
Sungwook Choi
committed
contains-duplicate
1 parent 84c2e41 commit 2750e33

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

contains-duplicate/csucom.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
#include <malloc.h>
3+
#include <string.h>
4+
5+
bool containsDuplicate(int* nums, int numsSize) {
6+
char* pflag = (char*)malloc(1000000001);
7+
char* mflag = (char*)malloc(1000000001);
8+
memset(pflag, 0, 1000000001);
9+
memset(mflag, 0, 1000000001);
10+
for (int i = 0; i < numsSize; ++i) {
11+
if (nums[i] < 0) {
12+
if (mflag[-nums[i]] == 1) {
13+
free(pflag);
14+
free(mflag);
15+
return true;
16+
}
17+
mflag[-nums[i]] = 1;
18+
}
19+
else {
20+
if (pflag[nums[i]] == 1) {
21+
free(pflag);
22+
free(mflag);
23+
return true;
24+
}
25+
pflag[nums[i]] = 1;
26+
}
27+
}
28+
free(pflag);
29+
free(mflag);
30+
return false;
31+
}
32+
33+
void main(void) {
34+
int test[100001] = {0};
35+
printf("%d\n", containsDuplicate(test, 1));
36+
}

0 commit comments

Comments
 (0)