문제: app.codility.com/programmers/lessons/10-prime_and_composite_numbers/flags/
Flags coding task - Learn to Code - Codility
Find the maximum number of flags that can be set on mountain peaks.
app.codility.com
결과: 20% 뭐지 이건..
if (A.Length < 3) return 0;
List<int> peek = new List<int>();
for (int i = 1; i < A.Length - 1; i++)
{
if (A[i] > A[i - 1] && A[i] > A[i + 1])
{
peek.Add(A[i]);
}
}
if (peek.Count < 1) return 0;
int before = peek[0];
int count = 1;
for (int i = 1; i < peek.Count; i++)
{
if (peek[i] != before)
count++;
before = peek[i];
}
return count;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson10. Peaks (C#) (0) | 2020.11.27 |
---|---|
[Codility] Lesson10. MinPerimeterRectangle (C#) (0) | 2020.11.27 |
[Codility] Lesson10. CountFactors (C#) (0) | 2020.11.20 |
[Codility] Lesson9. MaxSliceSum (C#) (0) | 2020.11.20 |
[Codility] Lesson9. MaxProfit (C#) (0) | 2020.11.20 |