꼬꼬마 개발자 노트/Coding Problems
프로그래머스 - 로또의 최고 순위와 최저 순위 (java)
Sueeeeee
2021. 10. 12. 12:23
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
class Solution {
private int right;
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int[2];
int count = 0;
right = 0;
int len = lottos.length;
for(int i =0; i<len ;i++){
int temp = lottos[i];
if(temp == 0){
count++;
}else {
checkRight(win_nums, temp);
}
}
answer[0] = check(count+right);
answer[1] = check(right);
return answer;
}
private int check(int num){
switch(num){
case 6 : return 1;
case 5 : return 2;
case 4 : return 3;
case 3 : return 4;
case 2 : return 5;
default : return 6;
}
}
private void checkRight(int[] win_nums, int temp){
int len = win_nums.length;
for(int j = 0; j<len;j++){
if(win_nums[j] == temp){
right++;
return;
}
}
}
}
|

반응형