[Programmers]-로또의 최고 순위와 최저 순위

문제

문제

문제

lottos배열은 내가 구매한 로또번호들 배열이다. 하지만 동생이 로또 용지에 낙서를 해서 보이지 않는부분이 있다. 그 부분은 0으로 표기하였다. win_nums배열은 당첨 번호들이다. 이 내용을 보고 당첨가능한 최고순위와 최저순위를 반환하면된다.

코드

import java.util.*;

class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {
        int[] answer = new int[2];
        ArrayList<Integer> lotto = new ArrayList<Integer>();
        ArrayList<Integer> win = new ArrayList<Integer>();
        
        int zero = 0;
        for(int a : lottos) {//list에 넣기
            if(a != 0) lotto.add(a);
            else zero++;
        }
        for(int b : win_nums) win.add(b);//list에 넣기
        
        int correct = 0;
        for(int a : lotto){
            if(win.contains(a)){//contains로 있으면
                correct++;
            }
        }
        
        int max = 7-(correct+zero);//최고순위
        int min = 7-correct;//최저순위
        if(max>6) max = 6;
        if(min>6) min = 6;
        
        answer[0] = max;
        answer[1] = min;
        return answer;
    }
}

코드 설명

주석에 설명 쉽게했다.

요약

  • 로또 되고싶다.