Lv1. 추억 점수

kik·2023년 8월 30일
0


  • 나의 풀이
import java.util.HashMap;
import java.util.Map;
class Solution {
    public int[] solution(String[] name, int[] yearning, String[][] photo) {
        int[] result = new int[photo.length];
       Map<String, Integer> map = new HashMap<String, Integer>();
       for(int i=0; i<name.length; i++) {
    	   map.put(name[i], yearning[i]);
       }
       for(int x=0; x<photo.length; x++) {
    	   int sum =0;
    	   for(int y=0; y<photo[x].length; y++) {
    		   if(map.containsKey(photo[x][y])) {
    			   sum = sum + map.get(photo[x][y]);
    		   }
    	   }
    	   result[x]=sum;
       }
       return result;
    }
}
  • 느낀점
    전에 map을 이용해 풀었던 문제가 생각나 이 문제도 map으로 푼 것이 뿌듯하기도 하고 기분도 좋은데 1점밖에 안줘서 다시 우울해졌다.
profile
신생아 개발자

0개의 댓글