文章目录
1 题目
2 解题思路
每两个数相加判断是否等于target
3 代码
/**
* 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* ret = (int*)malloc(sizeof(int)*2);
ret[0] = i;
ret[1] = j;
*returnSize = 2;
return ret;
}
}
}
*returnSize = 0;
return NULL;
}