Skip to main content
deleted 189 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

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.

You don't need Math.Abs
You are making 3 passes to get min, max, and maxIX - do it in one pass
Stop when min == 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 calculate without actually processing

You don't need Math.Abs. You are making 3 passes to get min, max, and maxIX - do it in one pass and stop when min == 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 calculated without actually processing.

added 5 characters in body
Source Link
paparazzo
  • 6k
  • 3
  • 19
  • 41

You don't need Math.Abs
You are making 3 passes to get min, max, and maxIX - do it in one pass
Stop when min == 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 calculate without actually processing

You don't need Math.Abs
You are making 3 passes to get min, max, and maxIX - do it in one pass
Stop when min == max

            min = max = num[0];
            maxIX = 0;
            for (int i = 1; i < nums.Length; i++)
            {
                if(nums[i] > max)
                {
                    max = nums[i];
                    maxIX = i;
                }
                if (nums[i] < min)
                    min = nums[i];
            }
            if (min != max)
            {
                 .... 
            }

The answer may be calculate without actually processing

You don't need Math.Abs
You are making 3 passes to get min, max, and maxIX - do it in one pass
Stop when min == 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 calculate without actually processing

deleted 30 characters in body
Source Link
paparazzo
  • 6k
  • 3
  • 19
  • 41

You don't need Math.Abs
You are making 3 passes to get min, max, and maxIX - do it in one pass
Stop when min == max

            min = Int32.MaxValue;
            max = -1;num[0];
            maxIX = -1;0;
            for (int i = 0;1; i < nums.Length; i++)
            {
                if(nums[i] > max)
                {
                    max = nums[i];
                    maxIX = i;
                }
                if (nums[i] < min)
                    min = nums[i];
            }
            if (min != max)
            {
                 .... 
            }

The answer may be calculate without actually processing

You don't need Math.Abs
You are making 3 passes to get min, max, and maxIX - do it in one pass
Stop when min == max

            min = Int32.MaxValue;
            max = -1;
            maxIX = -1;
            for (int i = 0; i < nums.Length; i++)
            {
                if(nums[i] > max)
                {
                    max = nums[i];
                    maxIX = i;
                }
                if (nums[i] < min)
                    min = nums[i];
            }
            if (min != max)
            {
                 .... 
            }

The answer may be calculate without actually processing

You don't need Math.Abs
You are making 3 passes to get min, max, and maxIX - do it in one pass
Stop when min == max

            min = max = num[0];
            maxIX = 0;
            for (int i = 1; i < nums.Length; i++)
            {
                if(nums[i] > max)
                {
                    max = nums[i];
                    maxIX = i;
                }
                if (nums[i] < min)
                    min = nums[i];
            }
            if (min != max)
            {
                 .... 
            }

The answer may be calculate without actually processing

added 12 characters in body
Source Link
paparazzo
  • 6k
  • 3
  • 19
  • 41
Loading
Source Link
paparazzo
  • 6k
  • 3
  • 19
  • 41
Loading