/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
//i遍历下标
for(int i = 0; i < numsSize; ++i){
//j遍历i之后的下标,因为题目要求数组同一元素不能重复出现
for(int j = i + 1; j < numsSize; ++j){
//找到了,动态开辟两个整数大小的空间存放下标
if(nums[i] + nums[j] == target){
int* ret = malloc(sizeof(int) * 2);
ret[0] = i, ret[1] = j;
*returnSize = 2;
return ret;
}
}
}
*returnSize = 0;
return NULL;
}
标签:numsSize,下标,暴力,returnSize,int,nums,ret,枚举,两数
From: https://blog.csdn.net/weixin_73483158/article/details/139216503