Contents
내가 작성한 코드
내가 작성한 코드
import java.util.*;
class Solution {
public int[] solution(String[] name, int[] yearning, String[][] photo) {
int[] answer = new int[photo.length];
Map<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]) {
// 해당 인물이 이름 목록에 있는지 확인하고 점수 합산
if(nameToYearning.containsKey(person)) {
totalYearning += nameToYearning.get(person);
}
}
answer[i] = totalYearning;
}
return answer;
}
}
Share article