关于Leecode在线编译刷题
/*给定一个整数数组 nums?和一个目标值 target,请你在该数组中找出和为目标值的那?两个?整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。
示例:
给定 nums = , target = 9
因为 nums + nums = 2 + 7 = 9
所以返回
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/two-sum
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。*/
#include <stdio.h>
#include <stdlib.h>
int *twoSum(int *nums, int numsSize, int target, int *returnSize)
{
int i = 0, j = 0, flag = 0;
returnSize = (int *)malloc(sizeof(int) * 2);
for (int x = 0; x < numsSize; x++)
{
int t = 0;
for (int y = 0; y < x; y++)
{
if (nums < nums)
{
t = nums;
nums = nums;
nums = t;
}
}
}
if ((target < nums + nums) || (target > nums + nums))
{
printf("超出范围\n");
returnSize = NULL;
returnSize = NULL;
}
else
{
for (i = 0, j = 0; i < numsSize; i++)
{
for (j = numsSize; j >= 0; j--)
{
if (nums + nums == target)
{
flag++;
if (flag > 0)
{
returnSize = i;
returnSize = j;
break;
}
}
}
if (flag > 0)
{
break;
}
}
if (flag < 1)
{
printf("NO NUMBER\n");
returnSize = 0;
returnSize = 0;
}
}
return returnSize;
}
int main(int argc, char const *argv[])
{
int arr[] = {2, 7, 11, 15};
int s = sizeof(arr) / sizeof(arr);
int key = 10;
int *result;
result = twoSum(arr, s, key, result);
printf("(%d , %d)", result, result);
return 0;
}
这段代码我在VScode运行正常
在Leecode在线编译器上一堆错误
solution.c: In function 'twoSum'
Line 23: Char 17: warning: assignment to 'int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
returnSize = NULL;
^
Line 24: Char 17: warning: assignment to 'int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
returnSize = NULL;
^
solution.c: At top level
Line 74: Char 5: error: conflicting types for 'main'
到底是咋回事
C++的编译要求更严格 问题是,我不知道错哪里了-_-|| 本帖最后由 Croper 于 2019-7-22 12:16 编辑
你别把main()给一起粘贴上去啊,
leetcode只要你给出要求的函数,别画蛇添足
页:
[1]