프로그래머스 - 로또의 최고 순위와 최저 순위

-·2022년 7월 23일
0
public int[] solution(int[] lottos, int[] win_nums) {
    int[] answer = new int[2];
    int total = 7;
    int findCnt = 0;
    int zeroCnt = 0;

    for (int i = 0; i < lottos.length; i++){
        final int cur = lottos[i];
        if(cur == 0){
            zeroCnt++;
        } else {
            if(Arrays.stream(win_nums).anyMatch(s -> s == cur)){
                findCnt++;
            }
        }
    }
    findCnt = total - findCnt;
    if(findCnt > 6) findCnt = 6;
    answer[1] = findCnt;

    findCnt -= zeroCnt;
    if(findCnt < 1) findCnt = 1;
    answer[0] = findCnt;
    return answer;
}

빈자리에 정답을 넣으면 무조건 순위가 올라가기 때문에

처음에 몇개맞는지를 구한다음 빈자리만큼 순위를 올려주면된다.

profile
거북이는 오늘도 걷는다

0개의 댓글