Skip to content

Commit f27e4c1

Browse files
committed
Time: 101 ms (72.32%), Space: 8.7 MB (28.9%) - LeetHub
1 parent 5908ebb commit f27e4c1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

0001-two-sum/0001-two-sum.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Note: The returned array must be malloced, assume caller calls free().
3+
*/
4+
int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
5+
6+
int* res = (int *)malloc(sizeof(int)*2);
7+
*returnSize = 2;
8+
9+
for(int i=0; i<numsSize; i++){
10+
for(int j=i+1; j<numsSize; j++){
11+
int a = nums[i];
12+
int b = nums[j];
13+
14+
if(a+b == target){
15+
res[0]=i;
16+
res[1]=j;
17+
return res;
18+
}
19+
}
20+
}
21+
22+
return res;
23+
24+
}

0 commit comments

Comments
 (0)