public int solution(int[] a) {
int[] count = new int[a.length];
int answer = 0;
for (int num : a)
count[num]++;
for (int i = 0; i < a.length; i++) {
if (count[i] == 0)
continue;
if (count[i] <= answer)
continue;
int length = 0;
for (int j = 0; j < a.length - 1; j++) {
if (a[j] != i && a[j + 1] != i)
continue;
if (a[j] == a[j + 1])
continue;
length++;
j++;
}
answer = Math.max(length, answer);
}
return answer * 2;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/70130