풀이
import java.util.*;
class Solution {
public int[] solution(int[] answers) {
int[] first = {1,2,3,4,5}; // 5개씩 반복
int[] second = {2,1,2,3,2,4,2,5}; // 8개씩 반복
int[] third = {3,3,1,1,2,2,4,4,5,5}; // 10개씩 반복
int[] score = {0,0,0}; // 각 수포자들의 점수
// 수포자들의 점수 계산
for(int i=0; i<answers.length; i++) {
if(answers[i] == first[i%5]) score[0]++;
if(answers[i] == second[i%8]) score[1]++;
if(answers[i] == third[i%10]) score[2]++;
}
// 최대 점수 구하기
int max = Math.max(score[0], Math.max(score[1], score[2]));
// 최대 점수를 가진 수포자 리스트 생성
List<Integer> answ = new ArrayList<Integer>();
for(int i=0; i<score.length; i++) if(max == score[i]) answ.add(i+1);
int[] answer = new int[answ.size()];
for(int i=0; i<answ.size(); i++){
answer[i] = answ.get(i);
}
return answer;
}
}
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr