力扣——两数之和

 1 /**
 2  * Note: The returned array must be malloced, assume caller calls free().
 3  */
 4 int* twoSum(int* nums, int numsSize, int target, int* returnSize){
 5   int i,j;
 6     int *result=NULL;
 7     for(i=0;i<numsSize-1;i++)
 8     {
 9         for(j=i+1;j<numsSize;j++)
10         {
11             if(nums[i]+nums[j]==target)
12             {
13                  result=(int*)malloc(sizeof(int)*2);
14                  result[0]=i;
15                  result[1]=j;
16                  return result;
17             }
18         }
19     }
20     return result;
21 }

结果输出  ]  ,也不知道哪错了,好纠结。

不过学到了哈希表,和动态数组的写法。还算是一种收获吧。 

原文地址:https://www.cnblogs.com/action0/p/11099471.html