class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int zerocnt = 0;
int matched = 0;
for(int i =0; i<6; i++) {
for(int j =0; j<6; j++) {
if(lottos[i] == win_nums[j]) matched++;
}
if(lottos[i]==0) zerocnt++;
}
int max= matched+zerocnt;
int min = matched;
int[] answer = {Math.min(7-max,6), Math.min(7-min,6)};
return answer;
}
}
일단 0의 갯수와 정답지와 일치하는 만큼 갯수를 센다.
max 값에 matched + zerocnt 값을 넣으면 (맞은갯수+알아볼수 없는 개수) , 즉 0값이 다 맞는다 가정하면된다.
min 값은 알아볼수 없는 로또 번호가 다 안맞았다고 가정하면 matched 값만큼 최저로 맞게된다.
만약 max값이 6이면 , 즉 1등이므로 answer에 순위를 대입하기위해 Math.min(7-max,6) 을 해주면 등수가 나오게된다.
마찬가지로 min도 똑같이 정답에 대입해주면된다.
'휴지통 > 알고리즘 & 자료구조' 카테고리의 다른 글
백준 10828 (0) | 2021.08.04 |
---|---|
백준 2839 (0) | 2021.08.03 |
백준 2775 (0) | 2021.07.28 |
백준 2750 (0) | 2021.07.28 |
백 트래킹(Back Tracking) (0) | 2021.07.24 |