Skip to content

Instantly share code, notes, and snippets.

@sholfen
Created November 9, 2015 07:03
Show Gist options
  • Save sholfen/d2a78effbb82e1d54045 to your computer and use it in GitHub Desktop.
Save sholfen/d2a78effbb82e1d54045 to your computer and use it in GitHub Desktop.
for Codility PermCheck
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PermCheck
{
class Program
{
static void Main(string[] args)
{
int[] A = { 4, 1, 3, 2 };
int[] B = { 4, 1, 3 };
Solution sol = new Solution();
Console.WriteLine(sol.solution(A));
Console.WriteLine(sol.solution(B));
}
}
public class Solution
{
public int solution(int[] input)
{
int isPermutation = 0;
bool[] checkList = new bool[input.Length + 1];
int count = 0;
for (int i = 0; i < input.Length; i++)
{
if (input[i] > input.Length)
{
break;
}
if (!checkList[input[i]])
{
checkList[input[i]] = true;
count += 1;
}
}
if (count == input.Length)
{
isPermutation = 1;
}
return isPermutation;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment