Created
November 9, 2015 07:03
-
-
Save sholfen/d2a78effbb82e1d54045 to your computer and use it in GitHub Desktop.
for Codility PermCheck
This file contains hidden or 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; | |
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