[레벨1] 로또의 최고 순위와 최저 순위 (JAVA)

Fekim·2022년 3월 14일
0

ps

목록 보기
39/48
class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {
        int[] answer = {6,6};
        int max = 7;
        int min = 7;
        
        for(int i=0; i<lottos.length; ++i){
        	// 가지고 있는 0의 갯수만큼 max 등수가 올라갈 수 있다.
            if(lottos[i] == 0){
                    max -= 1;
                }
            // 당첨번호와 일치하는 번호가 있다면, max와 min 등수 모두 올라간다. 
            for(int j=0; j<win_nums.length; ++j){
                if(lottos[i] == win_nums[j]){
                    max -= 1;
                    min -= 1;
                }
            }
            
        }
		
        // 2개를 맞아야 5등이다. max와 min을 6에서 시작했으므로
        // 하나도 당첨되지 않았을 시 7인 max와 min을 6으로 바꿔준다.
        if(max==7)
            max=6;
        if(min==7)
            min=6;
        
        answer[0] = max;
        answer[1] = min;
        
        return answer;
    }
}
profile
★Bugless 2024★

0개의 댓글