알고리즘
[Programmers]로또의 순위(난이도:★★★★)
BaekGyuHyeon
2022. 5. 16. 19:54
https://programmers.co.kr/learn/courses/30/lessons/77484
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
return solutionA(lottos,win_nums);
}
public int[] solutionA(int[] lottos,int[] win_nums){
int zeros = 0;
int matches = 0;
// 0의 개수 count
for(int i = 0 ; i < 6; i++){
if(lottos[i] == 0){
zeros++;
continue;
}
// 0이 아니라면 win_nums에 있는지 확인
for(int j = 0; j < 6; j++){
if(lottos[i] == win_nums[j]){
matches++;
break;
}
}
}
// 등수 계산
int max = 7 - (zeros+matches);
int min = 7 - matches;
max = Math.min(6,max);
min = Math.min(6,min);
return new int[]{max,min};
}
}