최대 1 분 소요

📁 [Lv1_77484] 로또의 최고 순위와 최저 순위

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

	        // 0의 개수 구하기
	        int cntZero = 0;
	        for(int i=0; i<lottos.length; i++)
	        {
	            if(lottos[i] == 0){
	                cntZero++;
	            }
	        }

	        // 기존 맞는 것들 구하기 ( 0제외 )
	        int cntSame=0;
	        for(int i=0; i<lottos.length; i++){
	            for(int j=0; j<win_nums.length;j++){
	                if(lottos[i] == win_nums[j]){
	                    cntSame++;
	                }
	            }
	        }

	        // 최고점수
	        int highest =((cntSame + cntZero) < 2 ? 6 : 7-(cntSame+cntZero));


	        // 최저점수
	        int lowest = (cntSame < 2 ? 6 : 7-cntSame);

	        answer[0] = highest;
	        answer[1] = lowest;



	        return answer;
	    }
	}

🤔 나의 생각

보기에는 어려워 보였지만 구조만 파악한다면 간단…
결론부터 말하면 로또의 최고 순위는 빈 숫자가 다 맞는 경우이고,
로또의 최저 순위는 빈 숫자가 다 틀린 경우이다.
그래서 먼저 빈 숫자의 개수를 체크해주고 , 다음에 기존에 있는 숫자들이 로또 번호와 맞는지 체크해서 그 두 수를 이용해서 풀어주었다.