Skip to content

Commit

Permalink
day6
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyLTY committed May 22, 2023
1 parent c309c2d commit de1b7f9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
18 changes: 18 additions & 0 deletions day4/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>

int cmp(const void* _a, const void* _b) {
int a = *(int*)_a, b = *(int*)_b;
return a - b;
}

void quicksort(int *low, int * high){

}

bool containsDuplicate(int* nums, int numsSize){

}

int main() {
return 0;
}
21 changes: 0 additions & 21 deletions day4/main.cpp

This file was deleted.

47 changes: 47 additions & 0 deletions day6/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <malloc.h>
#include <math.h>

int* intersect(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){
int n1[1001] = {0};
for (int i = 0; i < nums1Size; ++i) {
n1[nums1[i]]++;
}
int n2[1001] = {0};
for (int i = 0; i < nums2Size; ++i) {
n2[nums2[i]]++;
}

*returnSize = 0;
int* intersection = (int*)malloc(sizeof(int) * fmin(nums1Size, nums2Size));

for (int i = 0; i < 1001; ++i) {
if (n1[i] > 0 && n2[i] > 0) {
if (n1[i] < n2[i]) {
for (int j = 0; j < n1[i]; ++j) {
intersection[(*returnSize)++] = i;
}

} else{
for (int j = 0; j < n2[i]; ++j) {
intersection[(*returnSize)++] = i;
}
}

}
}

return intersection;
}

int main() {
int nums1[] = {4,9,5};
int nums2[] = {9,4,9,8,4};
int *returnSize = malloc(sizeof(int ));
int *a = intersect(nums1,3,nums2,5,returnSize);
for (int i = 0; i < *returnSize; ++i) {
printf("%d", a[i]);
}

return 0;
}

0 comments on commit de1b7f9

Please sign in to comment.