[풀이]
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
class Solution {
public int[] solution(String[] names, int[] yearning, String[][] photo) {
Map<String, Integer> map = new HashMap<>();
for(int i=0; i < names.length; i++){
map.put(names[i], yearning[i]);
}
int col = photo.length; //가로
int[] result = new int[col];
for(int i =0; i<col ; i++){
int num = 0;
for (String name : photo[i]){
if(map.containsKey(name)){
result[i] += map.get(name);
}
}
}
return result;
}
}
- 해당 점수를 맵에 넣어두고 photo를 돌때마다 해당 맵에 있는 키값이 있는지 확인하고 값을 더해준뒤 해당 점수를 돌려주면 끝.
'문제풀이 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] - 성격 유형 검사하기 (1) | 2023.04.08 |
---|---|
[프로그래머스] - 뒤에 있는 큰 수 찾기 (0) | 2023.04.04 |
[프로그래머스][조합] - 메뉴 리뉴얼 (0) | 2022.08.11 |
[프로그래머스] - 게임 맵 최단거리 (0) | 2022.08.09 |
[프로그래머스] - 문자열 다루기 기본 (0) | 2022.08.09 |