Sunday, May 29, 2016

PermCheck Codility Solution in C#.Net

PermCheck Codility Solution in C#.Net 


Check whether array A is a permutation.

Solution:

public static int PermCheck(int[] A)
        {
            int l = A.Length;
            int Result = 1;
            if (l == 0)
            {
                return Result = 1;
            }
            else
            {
                Array.Sort(A);
                for (int i = 0; i < l; i++)
                {
                    if (A[i] != (i + 1))
                    {
                        Result = 0;
                        break;
                    }
                }
                return Result;
            }
        }
And Here goes the Result, Got 100%




Perm Check

No comments:

Post a Comment