两数之和
题目
思路
暴力枚举:逐一遍历,将当前数与之后的数个个相加、判断其相加后是否等于target
代码实现
/*** Note: The returned array must be malloced, assume caller calls free().*///暴力枚举:
int* twoSum(int* nums, int numsSize, int target, int* returnSize)
{int index1=0,index2=0,flag=0;for(int i=0;i<numsSize;i++){for(int j=i+1;j<numsSize;j++){if(nums[i]+nums[j]==target){index1=i;index2=j;break;flag=1;}elsecontinue;}if(flag)break;}int* a=(int*)malloc(sizeof(int)*2);a[0]=index1;a[1]=index2;*returnSize=2;return a;
}