반응형
👇 문제 URL 👇
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int[2];
int cnt = 0;
int zeroCnt = 0;
for(int num : lottos){
if(num ==0){
zeroCnt ++;
}
for(int win_num : win_nums){
if(num == win_num){
cnt++;
}
}
}
int minCnt = cnt;
int maxCnt = cnt+zeroCnt;
answer[0] = getGrade(maxCnt);
answer[1] = getGrade(minCnt);
return answer;
}
public int getGrade(int cnt){
if(cnt == 6){
return 1;
}else if(cnt ==5){
return 2;
}else if(cnt ==4){
return 3;
}else if(cnt ==3){
return 4;
}else if(cnt ==2){
return 5;
}else{
return 6;
}
}
}
테스트 통과~!

728x90
반응형
'개발 > 알고리즘' 카테고리의 다른 글
[프로그래머스/JAVA] 숫자 문자열과 영단어 (0) | 2022.07.24 |
---|---|
[프로그래머스/JAVA] 신규 아이디 추천 (0) | 2022.07.24 |
[프로그래머스/JAVA] 신고 결과 받기 (1) | 2022.07.24 |
[프로그래머스/JAVA] 가장 큰 수 - 정렬 (0) | 2022.02.20 |
[프로그래머스/JAVA] K번째수 - 정렬 (0) | 2022.02.20 |
댓글