문제 https://school.programmers.co.kr/learn/courses/30/lessons/176963
photo에 등장하는 인물이 name에 있으면 yearning을 모두 더해 결과 배열에 저장한다.
// HashMap 사용
import java.util.*;
class Solution {
public int[] solution(String[] name, int[] yearning, String[][] photo) {
Map<String, Integer> hm = new HashMap<>();
int[] answer = new int[photo.length];
for(int i = 0 ; i < name.length ; i++){
hm.put(name[i], yearning[i]);
}
for(int i = 0 ; i < photo.length ; i++){
int sum = 0;
for(int j =0 ; j < photo[i].length ; j++){
if(hm.get(photo[i][j]) != null)
sum += hm.get(photo[i][j]);
}
answer[i] = sum;
}
return answer;
}
}