Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created March 6, 2018 05:23
Show Gist options
  • Save unilecs/d3183d5bbf2a8f8d7b0b733b85c98eb7 to your computer and use it in GitHub Desktop.
Save unilecs/d3183d5bbf2a8f8d7b0b733b85c98eb7 to your computer and use it in GitHub Desktop.
Задача 76: Перестановка массива
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