230814 추억 점수

Jongleee·2023년 8월 14일
0

TIL

목록 보기
337/737
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

0개의 댓글