Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int IntegersToCompleteArray(int[] testArray)
- { // before sorting array [ 9, 0, 3]
- Array.Sort(testArray);
- // after sorting array [ 0, 3, 9]
- int counter = 0;
- for (int i = 0; i < testArray.Length - 1; i++)
- {
- counter += testArray[i + 1] - testArray[i] - 1;
- //first iteration 0 += 3 - 0 -1 = 2
- //second iterations 2 += 9 - 3 - 1 = 7
- //third iteration 7 += ? - 9 - 1 iteration doesn't go?
- Console.WriteLine(counter);
- }
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement