-
-
Save unilecs/d3183d5bbf2a8f8d7b0b733b85c98eb7 to your computer and use it in GitHub Desktop.
Задача 76: Перестановка массива
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static int IsInversion(int[] arr) | |
{ | |
int length = arr.Length; | |
int[] hashArray = new int[length + 1]; | |
for (int i = 0; i < length; i++) | |
{ | |
int val = arr[i]; | |
if (val <= length) | |
{ | |
hashArray[val]++; | |
} | |
} | |
int k = 1; | |
for (k = 1; k <= length; k++) | |
{ | |
if (hashArray[k] == 0) | |
{ | |
break; | |
} | |
} | |
if (k <= length) | |
{ | |
return k; | |
} | |
return 0; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
int[] arr = new int[] { 1, 4, 2, 5, 6 }; | |
Console.WriteLine(string.Format("Answer = {0}", IsInversion(arr))); // 3 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment