보라코딩
프로그래머스 자바 :: 추억점 본문
HashMap이 바로 생각나서 쉽게 금방 풀었다!
map.containsKey(...) 를 사용하는 법도 배워 가자!
if(map.containsKey(person)){
import java.util.*;
class Solution {
public int[] solution(String[] name, int[] yearning, String[][] photo) {
int[] answer = new int[photo.length];
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < name.length; i++) {
map.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(map.get( photo[i][j] ) != null) {
sum += map.get( photo[i][j] );
}
}
answer[i] = sum;
}
return answer;
}
}
'프로그래머스 (java)' 카테고리의 다른 글
프로그래머스 자바 :: 신고 결과 받기 (0) | 2024.06.06 |
---|---|
프로그래머스 자바 :: 개인정보 수집 유효기간 (0) | 2024.05.26 |
프로그래머스 자바 :: PCCE 기출문제 9번 이웃한 칸 (0) | 2024.05.25 |
프로그래머스 자바 :: 달리기경주 (1단계) (0) | 2024.05.22 |
프로그래머스 자바 :: PCCE 기출문제 10번 데이터 분석 (0) | 2024.05.20 |