Advertisement
KonstantyNil

Untitled

Feb 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. static int IntegersToCompleteArray(int[] testArray)
  2.         {   // before sorting array [ 9, 0, 3]
  3.             Array.Sort(testArray);
  4.             // after sorting array [ 0, 3, 9]
  5.             int counter = 0;
  6.  
  7.             for (int i = 0; i < testArray.Length - 1; i++)
  8.             {
  9.                 counter += testArray[i + 1] - testArray[i] - 1;
  10.                 //first iteration 0 += 3 - 0 -1 = 2
  11.                 //second iterations 2 += 9 - 3 - 1 = 7
  12.                 //third iteration 7 += ? - 9 - 1 iteration doesn't go?
  13.                 Console.WriteLine(counter);
  14.             }
  15.  
  16.             return counter;
  17.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement