๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/์•Œ๊ณ ๋ฆฌ์ฆ˜

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„

by ynzu๐Ÿค 2022. 7. 24.
๋ฐ˜์‘ํ˜•

๐Ÿ‘‡ ๋ฌธ์ œ URL ๐Ÿ‘‡

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

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

        int cnt = 0;
        int zeroCnt = 0;
        for(int num : lottos){
        
            if(num ==0){
                zeroCnt ++;
            }
            
            for(int win_num : win_nums){
                if(num == win_num){
                    cnt++;
                }
            }

        }

        int minCnt = cnt;
        int maxCnt = cnt+zeroCnt;

        answer[0] = getGrade(maxCnt);
        answer[1] = getGrade(minCnt);

        return answer;
    }
    
     public int getGrade(int cnt){
        if(cnt == 6){
            return 1;
        }else if(cnt ==5){
            return 2;
        }else if(cnt ==4){
            return 3;
        }else if(cnt ==3){
            return 4;
        }else if(cnt ==2){
            return 5;
        }else{
            return 6;
        }
    }
}


ํ…Œ์ŠคํŠธ ํ†ต๊ณผ~!

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€