题解 | #两数之和#
两数之和
https://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
int* twoSum(int* numbers, int numbersLen, int target, int* returnSize ) { int i,j; int *arr=(int *)malloc(sizeof(int)*2); if(numbersLen==0) return NULL; *returnSize=2; for(i=0;i<numbersLen;i++) { if(numbers[i]>target) continue; for(j=i+1;j<numbersLen;j++) { if(numbers[i]+numbers[j]==target) { arr[0]=i+1; arr[1]=j+1; } } } return arr; }