Hello,
I am attempting to solve the Two Sum problem in the Leet Code compiler in C. It involves returning an array of two integer numbers.
The code works in an external compiler, but I am having trouble returning the array as the solution. The output shows up as ']' , when in reality it should be '[0,1]'.
Any tips/pointers? I have the enclosed below (once again, it is in C !) =>
/**
Note: The returned array must be malloced, assume caller calls free().
/
int twoSum(int* nums, int numsSize, int target, int* returnSize)
{
int b[numsSize]; //used in code
int result = (int)malloc(2 * sizeof(int));; //return array
int i,j;
b[0]=target - nums[0];
for(i=1;i<numsSize;i++)
{
for(j=0;j<i;j++)
{
if(b[j]==nums[i])
{
result[0]=j;
result[1]=i;
return result;
}
}
b[j]=target - nums[i];}
return;
}