Skip to content

Commit

Permalink
Time: 101 ms (72.32%), Space: 8.7 MB (28.9%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Dec 22, 2024
1 parent 5908ebb commit f27e4c1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 0001-two-sum/0001-two-sum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* twoSum(int* nums, int numsSize, int target, int* returnSize) {

int* res = (int *)malloc(sizeof(int)*2);
*returnSize = 2;

for(int i=0; i<numsSize; i++){
for(int j=i+1; j<numsSize; j++){
int a = nums[i];
int b = nums[j];

if(a+b == target){
res[0]=i;
res[1]=j;
return res;
}
}
}

return res;

}

0 comments on commit f27e4c1

Please sign in to comment.