본문 바로가기

공부하자/Codility

[Codility] Lesson4. FrogRiverOne (C#)

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

 

FrogRiverOne coding task - Learn to Code - Codility

Find the earliest time when a frog can jump to the other side of a river.

app.codility.com

 

            Hashtable all = new Hashtable(); // O(N)
            //List<int> all = new List<int>(); O(N**2)

            for (int i = 0; i < A.Length; i++)
            {
                if (A[i] <= X && !all.Contains(A[i]))
                    all.Add(A[i], A[i]);

                if (all.Count == X)
                    return i;
            }

            return -1;