hashMap 쓰는 부분과 그냥 하는 부분 코드 섞여있음.
import java.util.*;
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = {};
Map<Integer, Integer> lottoMap = new HashMap<Integer,Integer>();
lottoMap.put(6,1);
lottoMap.put(5,2);
lottoMap.put(4,3);
lottoMap.put(3,4);
lottoMap.put(2,5);
int matchCount = 0;
int zeroCount=0;
for(int i: lottos){
if(i==0) {
zeroCount++;
continue;}
for(int j : win_nums){
if(i==j){matchCount++;
break;}
}
}
int ans1 = lottoMap.getOrDefault(matchCount+zeroCount, 6);
int ans2 = lottoMap.getOrDefault(matchCount, 6);
int min = 7 - matchCount;
int max = 7 - (matchCount + zeroCount);
if(min > 6){min=6;}
if(max > 6){max=6;}
List<Integer> ans = new ArrayList<Integer>();
ans.add(max);
ans.add(min);
return ans.stream().mapToInt(i->i).toArray();
}
}
댓글