문제📜
https://programmers.co.kr/learn/courses/30/lessons/77484
나의 생각의 흐름💡
1) 0의 개수를 카운트 하자!
2) 당첨 번호와 맞는 개수를 카운트 하자!
3) 0과 맞는 개수로 최고 순위와 최저 순위를 구하자
나의 풀이🔑
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int cZero = countZero(lottos);
int cMatch = matchLottos(lottos,win_nums);
int[] answer = highChk(cZero,cMatch);
return answer;
}
//알아볼 수 없는 번호 Zero Count
public int countZero(int[] lottos){
int cZero = 0;
for(int i = 0; i<lottos.length; i++){
if(lottos[i]==0){
cZero++;
}
}
return cZero;
}
//당첨 번호와 맞는 번호의 개수
public int matchLottos(int [] lottos, int[] win_nums){
int cMatch = 0;
for(int i = 0; i<lottos.length; i++){
for(int j= 0; j<lottos.length; j++){
if(lottos[i]==win_nums[j]){
cMatch++;
}
}
}
return cMatch;
}
//최고 순위와 최저 순위 구하기
public int[] highChk(int cZero, int cMatch) {
int[] hChk = new int[2];
switch (cMatch+cZero) {
case 0: hChk[0] = 6;
break;
case 1: hChk[0] = 6;
break;
case 2: hChk[0] = 5;
break;
case 3: hChk[0] = 4;
break;
case 4: hChk[0] = 3;
break;
case 5: hChk[0] = 2;
break;
case 6: hChk[0] = 1;
break;
}
switch (cMatch) {
case 0: hChk[1] = 6;
break;
case 1: hChk[1] = 6;
break;
case 2: hChk[1] = 5;
break;
case 3: hChk[1] = 4;
break;
case 4: hChk[1] = 3;
break;
case 5: hChk[1] = 2;
break;
case 6: hChk[1] = 1;
break;
}
return hChk;
}
}
후기
사실 스위치를 써보고 싶었다
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스][LV.2] 더 맵게 (0) | 2022.04.29 |
---|---|
[프로그래머스][LV.1] 완주하지 못한 선수 (0) | 2022.04.27 |
댓글