Skip to content

Commit

Permalink
Merge pull request #663 from csucom/main
Browse files Browse the repository at this point in the history
[jejufather] Week 1
  • Loading branch information
SamTheKorean authored Dec 15, 2024
2 parents 2bc7a44 + 49876ae commit a43334e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions contains-duplicate/csucom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <malloc.h>
#include <string.h>

bool containsDuplicate(int* nums, int numsSize) {
char* pflag = (char*)malloc(1000000001);
char* mflag = (char*)malloc(1000000001);
memset(pflag, 0, 1000000001);
memset(mflag, 0, 1000000001);
for (int i = 0; i < numsSize; ++i) {
if (nums[i] < 0) {
if (mflag[-nums[i]] == 1) {
free(pflag);
free(mflag);
return true;
}
mflag[-nums[i]] = 1;
}
else {
if (pflag[nums[i]] == 1) {
free(pflag);
free(mflag);
return true;
}
pflag[nums[i]] = 1;
}
}
free(pflag);
free(mflag);
return false;
}


0 comments on commit a43334e

Please sign in to comment.