Home > Back-end >  Would you please tell me why everyone on Leetcode will show heap - buffer overflow, really can not f
Would you please tell me why everyone on Leetcode will show heap - buffer overflow, really can not f

Time:11-27

 int ina (int x, int * nums, int m) 
{

for(int i=0; i{
If (x==nums [I])
return 1;
}
return 0;
}

/* *
* Note: The returned array must be malloced, assume caller calls free ().
*/
Nums int * twoSum (int * and an int numsSize, int target, int * returnSize) {
Int * res=malloc (sizeof (int) * 2);
Int I, j, k=0, m=0;
for(i=0; i{
If (nums [I] & gt; Target) break;
for(j=i+1; j{
If (nums [j] & gt; Target) break;
If (nums nums [I] + [j]==target)
{
if(! Ina (I, res, m) & amp; & ! Ina (j, res, m))
{
Res [m]=I;
M++;
Res [m]=j;
M++;
}
The else
break;

}
}
}
* returnSize=m;
return res;

}

CodePudding user response:

Title number down, so to speak. Only code is not to understand the intention.

CodePudding user response:

Don't intent, affirmation is infinite recursion. Lead to base without thinking carefully.

CodePudding user response:

1. The sum of two Numbers

CodePudding user response:

This error is generally to memory cross-border
Such as you malloc 4 bytes of space to assign a value over and above what is 4 bytes will quote this wrong

You now malloc 8 bytes you following res [m]=j;
M is more than 2, is it to the wrong

CodePudding user response:

With q, the same problem when doing 3 sums

CodePudding user response:

Int * res=malloc (sizeof (int) * 2);//two size is enough?
if(! Ina (I, res, m) & amp; & ! Ina (j, res, m))//no res buffer before the assignment/initialize the parameters of the call or faulty?



  • Related