프로그래머스 - 추억점수

JIWOO YUN·2023년 3월 31일
0

문제링크

https://school.programmers.co.kr/learn/courses/30/lessons/176963

구현방법

이름과 매칭되는 값을 HashMap에 매칭시켜두고 각 phote에 있는 이름이 Map 의 포함되어 있는 경우 값을 더해주고 아닌 경우 넘어가서 계산합니다.

구현알고리즘

Hash Map

CODE

import java.util.HashMap;

public class Main {
}
class Solution {
    public int[] solution(String[] name, int[] yearning, String[][] photo) {
        int[] answer = new int[photo.length];
        HashMap<String,Integer> maps = new HashMap<>();
        for(int idx = 0; idx <name.length;idx++){
            maps.put(name[idx],yearning[idx]);
        }
        for(int row =0; row <photo.length;row++){
            for(int col = 0; col <photo[row].length;col++){
                if(maps.containsKey(photo[row][col]))
                {
                    answer[row] += maps.get(photo[row][col]);
                }
            }

        }
        return answer;
    }
}
profile
열심히하자

0개의 댓글