본문 바로가기

공부하자/Codility

[Codility] Lesson4. PermCheck (C#)

문제: app.codility.com/programmers/lessons/4-counting_elements/perm_check/

 

PermCheck coding task - Learn to Code - Codility

Check whether array A is a permutation.

app.codility.com

 

 

            List<int> ListA = new List<int>(A);
            ListA.Sort();
            int index = ListA.Count;

            if (index == 0)
                return 0;

            for (int i = 0; i < index; i++)
            {
                if (ListA[i] != i + 1)
                    return 0;
            }

            return 1;