728x90
반응형
문제
반응형
풀이
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
|
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int[2];
int count = 0; //읽을수 있는 숫자 중 맞춘 번호를 카운트
for(int i=0; i<lottos.length; i++) {
for(int j=0; j<win_nums.length; j++) {
if(lottos[i] == win_nums[j]) {
count++;
break;
}
}
}
int zero = 0; //읽을수 없는 숫자를 카운트
for(int i=0; i<lottos.length; i++) {
if(lottos[i] == 0) {
zero++;
}
}
int max = count + zero; //최대 일치 번호
int min = count; //최소 일치 번호
if(max == 1 || max == 0) max = 1;
if(min == 1 || min == 0) min = 1;
answer[0] = 7 - max; //일치 번호에 따른 순위 결정
answer[1] = 7 - min;
return answer;
}
|
cs |
728x90
반응형
'[JAVA] 프로그래머스 스쿨 > JAVA Lv.1' 카테고리의 다른 글
[프로그래머스/Java] Lv.1 숫자 문자열과 영단어 (0) | 2023.01.22 |
---|---|
[프로그래머스/Java] Lv.1 약수의 개수와 덧셈 (0) | 2023.01.22 |
[프로그래머스/Java] Lv.1 음양 더하기 (0) | 2023.01.22 |
[프로그래머스/Java] Lv.1 신규 아이디 추천 (0) | 2023.01.22 |
[프로그래머스/Java] Lv.1 내적 (0) | 2023.01.22 |