Skip to content

[jejufather] Week 1 #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Dec 15, 2024
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;
}


Loading