Time: 118 ms (83.18%), Space: 6.3 MB (64.58%) - LeetHub

This commit is contained in:
Deven
2023-04-14 19:07:12 -04:00
parent 3ad7d573d9
commit 93683d41b0
+19
View File
@@ -0,0 +1,19 @@
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* twoSum(int* nums, int numsSize, int target, int* returnSize){
for (int i = 0; i < numsSize; ++i) {
for (int j = i + 1; j < numsSize; ++j) {
if (nums[i] + nums[j] == target) {
int *returnPair = malloc(2 * sizeof(int));
returnPair[0] = i;
returnPair[1] = j;
*returnSize = 2;
return returnPair;
}
}
}
return NULL;
}