I guess this public int [] TwoSum (int [] Numbers, int target) statement is to define the array and the target,
But I don't understand public int usage, as well as the return of new int [] {I, j}; And return the new int [2]; What do you mean?
Public int [] TwoSum (int [] Numbers, int target)
{
For (int I=0; I & lt; Numbers. Length; I++)
{
For (int j=0; J & lt; Numbers. Length; J++)
{
If (I==j)
continue;
If (Numbers [I] + Numbers [j]==target)
Return new int [] {I, j};
}
}
Return new int [2];
}
CodePudding user response:
The other post I write my own:#include
Int main ()
{
Int num [10]={,9,17,21,35,99,333,128,101,121, 2};
int i,j;
for(i=0; I<=9; I++)
{
for(j=0; J<=9; J++)
{
If (num + num [I] [j]==120)
{
Printf (" % d % d ", I, j);
I=100;
}
}
}
}
CodePudding user response:
public int []
This is a C + + syntax, C language without public key;
Int [] such as the return value type is not common, common is int * return pointer, from the point of the return value of function is such, returns the pointer (address)
# include & lt; Stdio. H>
Int main ()
{
Int num [10]={,9,17,21,35,99,333,128,101,121, 2};
int i,j;
for(i=0; I<=9; I++)
{
for(j=0; J<=9; J++)
{
If (I.=j & amp; & Num + num [I] [j]==120)
{
Printf (" % d % d ", I, j);
//I=100;//this assignment will lead to an array, didn't end because the second cycle could, if (num [I] here will appear an array;
break;
}
}
If (j & lt;=9)//continue to jump out of the loop
break;
}
}
For your reference ~
A bit of a problem to repair the code, as above;
CodePudding user response:
Tell it like it is, in this section, this problem is to zhao old wet, you @ zhao old wet,