mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 118 ms (83.18%), Space: 6.3 MB (64.58%) - LeetHub
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user