my-solutions/problems/1-two-sum/lib.c

19 lines
474 B
C
Raw Normal View History

2022-11-17 15:45:40 +05:00
#include <stdlib.h>
#include "lib.h"
int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
for (int i=0; i<numsSize-1; i++) {
for (int j=i+1; j<numsSize; j++) {
if (nums[i] + nums[j] == target) {
int* res = malloc(2 * sizeof(int));
res[0] = i;
res[1] = j;
*returnSize = 2;
return res;
}
}
}
*returnSize = 0;
return NULL;
}