[JAVA 문제 풀이] 283. 모의고사

프로그래머스 (42840)
Stupefyee's avatar
May 28, 2025
[JAVA 문제 풀이] 283. 모의고사
notion image
 

내가 작성한 코드

import java.util.*; class Solution { public int[] solution(int[] answers) { int[] stu1 = {1, 2, 3, 4, 5}; int[] stu2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] stu3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; int stu1count = 0; int stu2count = 0; int stu3count = 0; for(int i = 0; i < answers.length; i++) { if (answers[i] == stu1[i % stu1.length]) { stu1count++; } if (answers[i] == stu2[i % stu2.length]) { stu2count++; } if (answers[i] == stu3[i % stu3.length]) { stu3count++; } } int max = Math.max(stu1count, Math.max(stu2count, stu3count)); List<Integer> list = new ArrayList<>(); if (stu1count == max) { list.add(1); } if (stu2count == max) { list.add(2); } if (stu3count == max) { list.add(3); } return list.stream().mapToInt(i -> i).toArray(); } }
Share article

stupefyee