mirror of
https://github.com/TheAlgorithms/C
synced 2025-04-22 13:16:14 +03:00
15 lines
385 B
C
15 lines
385 B
C
int* twoSum(int* nums, int numsSize, int target, int* returnSize){
|
|
int i, j;
|
|
int *ret = calloc(2, sizeof(int));
|
|
for (i = 0; i < numsSize; i++) {
|
|
int key = target - nums[i];
|
|
for (j = i + 1; j < numsSize; j++)
|
|
if (nums[j] == key) {
|
|
ret[0] = i;
|
|
ret[1] = j;
|
|
}
|
|
}
|
|
*returnSize = 2;
|
|
return ret;
|
|
}
|