728x90
반응형
Java
import java.util.*;
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int[2];
int[] rank = {6, 6, 5, 4, 3, 2, 1};
int count = 0;
int i;
Arrays.sort(lottos);
for(i = lottos.length - 1; i >= 0 && lottos[i] > 0; i--){//i + 1이 0 개수
for(int j = 0; j < win_nums.length; j++){
if(lottos[i] == win_nums[j]){
count++;
break;
}
}
}
answer[0] = rank[count + i + 1];
answer[1] = rank[count];
return answer;
}
}
Python
def solution(lottos, win_nums):
answer = []
rank = [6, 6, 5, 4, 3, 2, 1]
count = 0
for element in lottos:
if element in win_nums:
count += 1
answer.append(rank[count + lottos.count(0)])
answer.append(rank[count])
return answer
728x90
반응형
'프로그래머스 > LEVEL 1' 카테고리의 다른 글
Go K번째수 (1) | 2021.08.17 |
---|---|
약수의 개수와 덧셈 (0) | 2021.06.13 |
x만큼 간격이 있는 n개의 숫자 (0) | 2021.03.07 |
소수 만들기 (0) | 2021.03.07 |
직사각형 별찍기 (0) | 2021.03.07 |