You don't need MathMath.Abs
.Abs
You You are making 3 passes to get minmin
, maxmax
, and maxIX maxIX
- do it in one pass
Stop and stop when min == maxmin == max
.
min = max = num[0];
maxIX = 0;
for (int i = 1; i < nums.Length; i++)
{
if(nums[i] > max)
{
max = nums[i];
maxIX = i;
}
else if (nums[i] < min)
min = nums[i];
}
if (min != max)
{
....
}
The answer may be calculatecalculated without actually processing.