class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int [2];
int match = 0;
for(int i = 0; i<lottos.length; i++) {
for(int j = 0; j<win_nums.length; j++) {
if(lottos[i]==win_nums[j]) {
match++;
}
}
}
int zero = 0;
for(int i: lottos) if(i==0) zero++;
answer[0] = 6-match+zero+1;
answer[1] = 6-match+1;
if(answer[0]==7) answer[0] = 6;
if(answer[1]==7) answer[1] = 6;
return answer;
}
}
1. 최고, 최저의 배열의 크기를 2로 고정
2. 일치하는 개수와 0이 있는 개수를 구한다
3. 최고 , 최저 순위를 배열안에 넣어준다. 다 틀렸을 경우가 예외가 되는데 그 때에 if문으로 순위를 바꿔준다.
'코딩테스트 문제풀이' 카테고리의 다른 글
프로그래머스 (아이디 추천 ) (0) | 2021.09.08 |
---|---|
3519 : Tutorial : 합병(병합)정렬(Merge Sort) -(JUNGOL) (0) | 2021.09.07 |
프로그래머스-내적 (0) | 2021.08.12 |
프로그래머스 - 소수 만들기 (0) | 2021.08.11 |
프로그래머스 위클리 챌린지 2주차 (0) | 2021.08.09 |