정답
import java.util.*;
class Solution {
public int[] solution(int[] answers) {
/*
pickArr1 1,2,3,4,5
pickArr2 2,1,2,3,2,4,2,5
pickArr3 3,3,1,1,2,2,4,4,5,5
*/
int[] pickArr1 = {1,2,3,4,5}; //5
int[] pickArr2 = {2,1,2,3,2,4,2,5}; //8
int[] pickArr3 = {3,3,1,1,2,2,4,4,5,5}; //10
int[] resultArr = new int[3];
//12345 % 5 4-4 5-5 0
int index = 0;
for(int answer : answers){
if(pickArr1[index % 5] == answer){
resultArr[0]++;
}
if(pickArr2[index % 8] == answer){
resultArr[1]++;
}
if(pickArr3[index % 10] == answer){
resultArr[2]++;
}
index++;
}
int max = -1;
for(int result : resultArr){
if(result > max){
max = result;
}
}
List<Integer> maxList = new ArrayList<>();
for(int i=0; i<resultArr.length; i++){
if(max == resultArr[i]){
maxList.add(i+1);
}
}
int[] maxPersonArr = new int[maxList.size()];
int maxPersonCount = 0;
for(int maxPerson : maxList){
maxPersonArr[maxPersonCount] = maxPerson;
maxPersonCount++;
}
Arrays.sort(maxPersonArr);
return maxPersonArr;
}
}