https://programmers.co.kr/learn/courses/30/lessons/77484
Problem
Code
import java.util.*;
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int[2];
Arrays.sort(lottos);
Arrays.sort(win_nums);
int p1 = 0, p2 = 0;
int invisibleCnt = 0;
int matched = 0;
while(p1 < 6 && p2 <6) {
if (lottos[p1] == 0) {
invisibleCnt++;
p1++;
} else {
if (lottos[p1] == win_nums[p2]) {
matched++;
p1++;
p2++;
} else if (lottos[p1] < win_nums[p2]) {
p1++;
} else {
p2++;
}
}
}
answer[1] = 6 - matched + 1;
if (answer[1] > 6) answer[1] =6;
if (invisibleCnt <= (6 - matched)) {
matched += invisibleCnt;
} else {
matched += (6 - matched);
}
answer[0] = 6 - matched + 1;
if (answer[0] > 6) answer[0] =6;
return answer;
}
}