Skip to content

Commit

Permalink
로또의 최고 순위와 최저 순위
Browse files Browse the repository at this point in the history
  • Loading branch information
sey2 authored Aug 15, 2022
1 parent 660c4fe commit cbf4e42
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions programmers/Lotto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.*;

class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int correct = 0;
int zeroCnt = 0;

for(int i=0; i<win_nums.length; i++){
for(int j=0; j<lottos.length; j++){

if(lottos[j] == 0 && i == 0){
zeroCnt++;
continue;
}
else if(lottos[j] == win_nums[i]) correct++;
}
}


int[] answer = new int[2];

answer[1] = rank(correct);
correct += zeroCnt;
answer[0] = rank(correct);

return answer;
}

public static int rank(int correct){
switch(correct){
case 6: return 1;
case 5: return 2;
case 4: return 3;
case 3: return 4;
case 2: return 5;
default: return 6;
}
}
}

0 comments on commit cbf4e42

Please sign in to comment.