본문 바로가기

카테고리 없음

프로그래머스_LEVEL1_추억 점수

해쉬맵을 사용하여서 키와 밸류값으로 처리하는 문제이다.

 

import java.util.HashMap;

class Solution {
    public int[] solution(String[] name, int[] yearning, String[][] photo) {
        int woo=photo.length;
        int[] answer = new int[woo];
        HashMap<String,Integer> myMap=new HashMap<String,Integer>();
        for(int i=0; i<yearning.length; i++){
            myMap.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(myMap.containsKey(photo[i][j])){
                sum+=myMap.get(photo[i][j]);
                }
                else{
                    sum+=0;
                }
            }
            answer[i]=sum;
        }
        return answer;
    }
}