본문 바로가기

코딩테스트(프로그래머스)/LEVEL 1

[프로그래머스/Java] 모의고사 - 사좋배 공유 -

*문제 설명

 

 

* 풀이

 

import java.util.*;
class Solution {
    
    public int[] solution(int[] answers) {
        int count[]= new int[3];
        int []A = {1,2,3,4,5};
        int []B = {2,1,2,3,2,4,2,5};
        int []C = {3,3,1,1,2,2,4,4,5,5};
     
        for(int i=0;i<answers.length;i++){
            if(A[i%5]==answers[i]){
                count[0]++;
            }
            if(B[i%8]==answers[i]){
                count[1]++;
            }
            if(C[i%10]==answers[i]){
                count[2]++;
            }   
        }
            
            
        int max=count[0];
        
        for(int i=0;i<count.length;i++){
            if(count[i]>max){
                max=count[i];
            }
        }
        
   
        
        Listwin = new ArrayList<>();
     
        for(int i=0;i<count.length;i++){
            if(count[i]==max){
                win.add(i);
            }
        }
        int answer[] = new int[win.size()];
        for(int i=0;i<answer.length;i++){
            answer[i]=win.get(i)+1;
        }
       
        return answer;
        
        
            
    }
}