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

J_C·2021년 6월 27일
0

로또의 최고 순위와 최저 순위 Go

내풀이

import java.util.*;
class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {
        int[] answer =  new int[2];
        int correct_num =0;
        int high_rank=7,low_rank = 7;
        for(int i = 0;i < lottos.length;i++){
            if(lottos[i]==0){
                high_rank--;
                continue;
            }
            for(int j = 0;j < win_nums.length;j++){
                if(lottos[i] == win_nums[j]){
                    correct_num++;
                }
            }
        }
        low_rank -= correct_num;
        high_rank -= correct_num;
        
        if(high_rank == 7) {
            high_rank = 6;
        } if(low_rank == 7){
            low_rank = 6;
        } 
        answer[0] = high_rank;
        answer[1] = low_rank;
        return answer;
    }
}
profile
jiyeonsama

0개의 댓글