ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

https://programmers.co.kr/learn/courses/30/lessons/77484

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„

๋กœ๋˜ 6/45(์ดํ•˜ '๋กœ๋˜'๋กœ ํ‘œ๊ธฐ)๋Š” 1๋ถ€ํ„ฐ 45๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ 6๊ฐœ๋ฅผ ์ฐ์–ด์„œ ๋งžํžˆ๋Š” ๋Œ€ํ‘œ์ ์ธ ๋ณต๊ถŒ์ž…๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ๋กœ๋˜์˜ ์ˆœ์œ„๋ฅผ ์ •ํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. 1 ์ˆœ์œ„ ๋‹น์ฒจ ๋‚ด์šฉ 1 6๊ฐœ ๋ฒˆํ˜ธ๊ฐ€ ๋ชจ๋‘ ์ผ์น˜ 2 5๊ฐœ ๋ฒˆํ˜ธ

programmers.co.kr

[๋ฌธ์ œ ํ’€์ด]

lottos ๋ฐฐ์—ด์— ์žˆ๋Š” 0์˜ ๊ฐ’๋“ค์ด ํ•ต์‹ฌ์ž…๋‹ˆ๋‹ค.

- lottos๋ฐฐ์—ด์—์„œ ๋‹น์ฒจ ๋ฒˆํ˜ธ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•ด min์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

- lottos๋ฐฐ์—ด์—์„œ 0์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•ด zero์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

- 0์ด ๋ชจ๋‘ ๋ฏธ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ผ๊ณ  ๊ฐ€์ •ํ•˜๋ฉด, min์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ˆœ์œ„๋ฅผ ๊ฒฐ์ •ํ•˜๊ณ , 0์ด ๋ชจ๋‘ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ผ๋ฉด min + zero๊ฐ€ ์ˆœ์œ„๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

 

[์ •๋‹ต ์ฝ”๋“œ]

import java.util.*;
class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {
        int[] answer = new int[2];
        int min = 0;
        int zero = 0;
        ArrayList<Integer> winNum = new ArrayList<Integer>();
        for(int i=0;i<win_nums.length;i++) {
            winNum.add(win_nums[i]);
        }
        for(int i=0;i<lottos.length;i++) {
            if(lottos[i] > 0) {
                if(winNum.contains(lottos[i])) {
                    min++;   
                }
            } else {
                zero++;
            }
        }
        answer[0] = getGrade(min + zero);
        answer[1] = getGrade(min);
        return answer;
    }
    public static int getGrade(int cnt) {
        int result = 7 - cnt;
        if(result > 6) {
            return 6;
        }
        return result;
    }
}
/*
lottos์ค‘์—์„œ 0๊ฐœ์ˆ˜ ์ฐพ์•„๋‘  (๋ณ€ํ• ์ˆ˜ ์žˆ๋Š” ๊ฐ’)
lottos์ค‘ 0์ด ์•„๋‹Œ๊ฑฐ ์ฐพ์•„์„œ win_nums๋ž‘ ์ผ์น˜ํ•˜๋Š”๊ฑฐ ์ฐพ์•„๋‘ 
*/