[프로그래머스] 모의고사

최대 1 분 소요

모의고사

import java.util.*;

class Solution {

    public int[] solution(int[] answers) {
        int[] people1 = {1,2,3,4,5};
        int[] people2 = {2,1,2,3,2,4,2,5};
        int[] people3 = {3,3,1,1,2,2,4,4,5,5};
        int count=0;
        int check[]=new int[3];
        int temp=0;

        while(count<answers.length){
            if(answers[count]==people1[count%5])
                check[0]++;
            if(answers[count]==people2[count%8])
                check[1]++;
            if(answers[count]==people3[count%10])
                check[2]++;
            count++;
        }
        temp=check[0]>=check[1] ? check[0] : check[1];
        temp=temp>=check[2] ? temp : check[2];
        count=0;
        for(int i=0;i<check.length;i++){
            if(temp==check[i]){
                count++;
            }
        }
        int[] answer = new int[count];
        count=0;
        for(int i=0;i<check.length;i++){
            if(temp==check[i]){
                answer[count]=i+1;
                count++;
            }
        }
        return answer;
    }
}