프로그래머스 - 추억 점수

차관호·2023년 8월 8일

문제링크 - 프로그래머스 - 추억 점수

import java.util.*;

class Solution {
    public int[] solution(String[] name, int[] yearning, String[][] photo) {
         int[] answer = new int[photo.length];

        Map<String, Integer> map = new HashMap<>();

        for(int i = 0; i < name.length; i++){
            String realName = name[i];
            int score = yearning[i];

            map.put(realName, score);
        }
        // 해시 맵 완성
        for(int i = 0; i < photo.length; i++){
            int sum = 0;
            for(String a : photo[i]){
                answer[i] += map.getOrDefault(a,0);
            }
        }
        return answer;
    }   
}
profile
안녕하세요 :-)

1개의 댓글

comment-user-thumbnail
2023년 8월 8일

많은 도움이 되었습니다, 감사합니다.

답글 달기