int* twoSum(int* nums, int numsSize, int target, int* returnSize){
int i = 0, j = 0;
for(i=0; i < numsSize; i++)
{
for(j = i+1; j < numsSize; j++)
{
if(nums[j] == target - nums[i])
{
int *index = (int *)malloc(sizeof(int) * 2);
index[0] = i;
index[1] = j;
return index;
}
}
}
return NULL;
}
I was writing the code for the following
Given nums = [2, 7, 11, 15]
, target = 9
,
Because nums[0] + nums[1] = 2 + 7 = 9
,
return [0, 1]
.
I tried debugging the code, i and j values 0 and 1 as expected. But now I'am facing the issue while returning the index. It is showing as segmentation fault. Can anyone please correct the above code?