알고리즘
[프로그래머스] 추억점수
pooney
2023. 6. 4. 23:38
public int[] solution(String[] name, int[] yearning, String[][] photo) {
int [] answer = new int[photo.length];
Map<String,Integer> nameMap = new HashMap<>();
for(int i=0; i<name.length; i++){
nameMap.put(name[i],yearning[i]);
}
int i = 0;
for(String[] p : photo ){
int sum = 0;
for(String v : p ) {
if(nameMap.get(v) != null){
sum += nameMap.get(v);
}
}
answer[i] = sum;
i++;
}
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/176963