题目1. 两数之和
https://leetcode-cn.com/problems/two-sum/
题目
解题思路
方法1:暴力枚举
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* twoSum(int* nums, int numsSize, int target, int* returnSize){
int *ans = (int *)malloc(sizeof(int)*2);
for(int i = 0;i<numsSize-1;i++){
for(int j = i+1;j<numsSize;j++){
if(i == j){
continue;
}
if(nums[i]+nums[j] == target){
ans[0] = i;
ans[1] = j;
*returnSize = 2;
return ans;
}
}
}
*returnSize = 0;
return ans;
}
方法2: 哈希表
待补充:参考