본문 바로가기
개발/알고리즘

[프로그래머스/JAVA] 로또의 최고 순위와 최저 순위

by zuzuu 2022. 7. 24.
반응형

👇 문제 URL 👇

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {
        int[] answer = new int[2];

        int cnt = 0;
        int zeroCnt = 0;
        for(int num : lottos){
        
            if(num ==0){
                zeroCnt ++;
            }
            
            for(int win_num : win_nums){
                if(num == win_num){
                    cnt++;
                }
            }

        }

        int minCnt = cnt;
        int maxCnt = cnt+zeroCnt;

        answer[0] = getGrade(maxCnt);
        answer[1] = getGrade(minCnt);

        return answer;
    }
    
     public int getGrade(int cnt){
        if(cnt == 6){
            return 1;
        }else if(cnt ==5){
            return 2;
        }else if(cnt ==4){
            return 3;
        }else if(cnt ==3){
            return 4;
        }else if(cnt ==2){
            return 5;
        }else{
            return 6;
        }
    }
}


테스트 통과~!

728x90
반응형

댓글