코딩테스트

[코딩테스트(Java)] 프로그래머스 77484 로또의 최고 순위와 최저 순위

inhooo00 2025. 3. 12. 10:34

https://school.programmers.co.kr/learn/courses/30/lessons/77484

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

public int[] solution(int[] lottos, int[] win_nums) {
    int[] answer = new int[2];
    int countZ = 0; // 0 개수
    int countNum = 0; // 맞춘 숫자
    for (int i = 0; i < lottos.length; i++) {
        if (lottos[i] == 0) {
            countZ++;
        }
    }

    for (int i = 0; i < lottos.length; i++) {
        for (int j = 0; j < win_nums.length; j++) {
            if (lottos[i] == win_nums[j]) {
                countNum++;
            }
        }
    }

    if (countZ == 6 || countNum == 1 || countNum == 0) { // 최소 등수 구하기
        answer[1] = 6;
    } else {
        answer[1] = 7 - countNum;

    }

    if (answer[1] - countZ > 1) { // 최대 등수 구하기
        answer[0] = answer[1] - countZ;
    } else {
        answer[0] = 1;
    }
    
    return answer;
}

 

 

 

📍포인트

1. 쉬웠음