Created
December 3, 2020 20:33
-
-
Save kingsamadesu/64ab29b9dde0e3cb89df946e1acfed54 to your computer and use it in GitHub Desktop.
1. Two Sum -with c- (leetcode.com)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Note: The returned array must be malloced, assume caller calls free(). | |
*/ | |
int* twoSum(int* nums, int numsSize, int target, int* returnSize){ | |
int* returnArray = malloc(2*sizeof(int)); | |
if (numsSize ==2){ | |
returnArray[0]=0; | |
returnArray[1]=1; | |
return returnArray; | |
} | |
for (int i=0; i<numsSize-1;i++){ | |
for (int j=i+1; j<numsSize;j++){ | |
if (nums[i]+nums[j]==target){ | |
returnArray[0]=i; | |
returnArray[1]=j; | |
return returnArray; | |
} | |
} | |
} | |
return returnArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment