본문 바로가기
Beakjoon&프로그래머스/Java

[프로그래머스/Java] 추억 점수

by 현장 2025. 2. 26.

-Code

import java.util.*;

class Solution {
    public int[] solution(String[] name, int[] yearning, String[][] photo) {
        List<Integer> answer = new ArrayList<>();
        for (String[] line : photo) {
            List<String> now = List.of(line);
            int res = 0;
            for (int i = 0; i < name.length; i++) {
                if (now.contains(name[i])) res += yearning[i];
            }
            answer.add(res);
        }
        
        return answer.stream().mapToInt(Integer::intValue).toArray();
    }
}