public int[] solution(String[] name, int[] yearning, String[][] photo) {
int[] answer = new int[photo.length];
HashMap<String, Integer> nameToYearning = new HashMap<>();
for (int i = 0; i < name.length; i++) {
nameToYearning.put(name[i], yearning[i]);
}
for (int i = 0; i < photo.length; i++) {
int totalYearning = 0;
for (String person : photo[i]) {
totalYearning += nameToYearning.getOrDefault(person, 0);
}
answer[i] = totalYearning;
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/176963