본문 바로가기
Beakjoon&프로그래머스/Java

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

by 현장 2025. 3. 1.

-Code

import java.util.*;
import java.util.stream.Collectors;

class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {
        List<Integer> win_list = Arrays.stream(win_nums)
                .boxed().collect(Collectors.toList());
        int current_cnt = 0, zero_cnt = 0;
        for (int n : lottos) {
            if (n == 0) {
                zero_cnt++;
                continue;
            }
            if (win_list.contains(n)) {
                current_cnt++;
            }
        }
        int low= 7 - current_cnt, high = 7 - current_cnt - zero_cnt;
        return new int[] {high == 7 ? 6 : high, low == 7 ? 6 : low};
    }
}