import java.util.*;

class Solution {
    public int[] solution(int[] answers) {
        int[][] mathFail = new int[][] {{1,2,3,4,5}, {2,1,2,3,2,4,2,5}, {3,3,1,1,2,2,4,4,5,5}};       
        int[] score = new int[3];
        
        for(int i=0; i<3; i++) {
            for(int j=0; j<answers.length; j++) {
                int index = j%mathFail[i].length;
                if(answers[j]==mathFail[i][index]) { score[i]++; }
            }
        }

        int max = Math.max(score[0], Math.max(score[1], score[2]));
        List<Integer> list = new ArrayList<>();
        
        for(int i=0; i<3; i++) {
            if(max==score[i]) { list.add(i+1); }
        }
        
        int[] answer = new int[list.size()];
        for(int i=0; i<answer.length; i++) { answer[i] = list.get(i); }
        
        return answer;
    }
    
}

'Problem Solving > Programmers' 카테고리의 다른 글

[Level 1] 폰켓몬  (0) 2022.03.23
[Level 1] 체육복  (0) 2022.03.23
[Level 1] K번째수  (0) 2022.03.23
[Level 1] 완주하지 못한 선수  (0) 2022.03.23
[Level 1] 소수 만들기  (0) 2022.03.23