inblog logo
|
stupefyee
    알고리즘문제풀기

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

    프로그래머스 (42840)
    Stupefyee's avatar
    Stupefyee
    May 28, 2025
    [JAVA 문제 풀이] 283. 모의고사
    Contents
    내가 작성한 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/42840
    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
    Contents
    내가 작성한 코드

    stupefyee

    RSS·Powered by Inblog