Home > Back-end >  The 2020-11-07: known to be a positive integer array, addition of two Numbers is equal to N and ther
The 2020-11-07: known to be a positive integer array, addition of two Numbers is equal to N and ther

Time:11-08

The 2020-11-07: known to be a positive integer array, addition of two Numbers is equal to N and there must be, how to find the minimum two multiplication of two Numbers? # # f greatly architects a daily topic

CodePudding user response:

Arrange an array by size, take the first and second number multiplication is the smallest

CodePudding user response:

Here only ideas, regardless of the multiplication int beyond the scope of the
In turn over the array elements, to determine N - whether the current element in the array also exist (guarantee and for N), if there is a product of the calculation, and save the minimum product
Int min=Integer. MAX_VALUE;//minimum product initial value
for (int i=0; iInt TMP=N - a [I];//a and N - [I] a [I] is two and the number of N
If (tmp>=0) {
//if N - a [I] in the array, and the two Numbers multiplied Int. Independence idx=Aarays binarySearch (a, TMP);
If (independence idx!=1 & amp; & Independence idx!=I & amp; & (TMP=a [I] * TMP) & lt; Min) {
Min=TMP;//save the latest min
}
}
}
System. The out. Println (min);
  • Related