문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/77484
class Solution { private int findScore(int value) { if (value == 6) { return 1; } else if (value == 5) { return 2; } else if (value == 4) { return 3; } else if (value == 3) { return 4; } else if (value == 2) { return 5; } else { return 6; } }
private int[] cmpStrings(int[] lottos, int[] win_nums) { int[] result = new int[2]; int length = lottos.length;
int zeroCnt = 0; int sameCnt = 0;
for (int i = 0; i < length; i++) { if (lottos[i] == 0) { zeroCnt++; continue; }
for (int j = 0; j < length; j++) { if (lottos[i] == win_nums[j]) { sameCnt++; } } }
result[0] = findScore(sameCnt + zeroCnt); result[1] = findScore(sameCnt);
return result; }
public int[] solution(int[] lottos, int[] win_nums) { int[] answer = new int[2]; answer = cmpStrings(lottos, win_nums);
return answer; } }
|