题目:给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
你可以按任意顺序返回答案。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/two-sum
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
以下是我的解题代码:
/**
- Note: The returned array must be malloced, assume caller calls free().
- /
int* twoSum(int* nums, int numsSize, int target, int* returnSize){
int i,k,fg=0;
int ret[2]={0};
for(i=0;i<numsSize;i++){
}fg=target-nums[i]; for(int k = i+1;k<numsSize;k++) { if(fg==nums[k]) { printf("[%d,%d]",k,i); break; } }
ret[0]=i;
ret[1]=k;
return ret;
}
用C语言写的代码 然后力扣表示我的输出只有一个“[”
我还特意用printf打印了一下 能打印出正确的结果 但是打印不算 一定要函数返回的数组