배운점
- 달리기 경주를 풀고 나니 Map에 조금 익숙해져서 Map을 사용하였다. 조건을 제대로 안읽어서 그리움 점수가 없는 경우를 고려하지 않아 null 에러가 발생했지만 에러 처리를 해주니 코드가 정상 작동 하였다.
import java.util.*; class Solution { public int[] solution(String[] name, int[] yearning, String[][] photo) { int[] answer = new int[photo.length]; Map<String, Integer> score = new HashMap<String, Integer>(); for(int i = 0; i < name.length; i++){ score.put(name[i], yearning[i]); } for(int i = 0; i < photo.length; i++) { for(int j = 0; j < photo[i].length; j++){ if(score.get(photo[i][j]) != null) answer[i] += score.get(photo[i][j]); } } return answer; } } |
'코딩테스트' 카테고리의 다른 글
[프로그래머스] Level1 공원 산책 JAVA (1) | 2023.10.12 |
---|---|
[프로그래머스] Level1 달리기 경주 JAVA (0) | 2023.10.11 |
[프로그래머스]2021 KAKAO BLIND RECRUITMENT 신규 아이디 추천 JAVA (0) | 2023.09.07 |
[프로그래머스] 2019 카카오 개발자 겨울 인턴십 - 크레인 인형뽑기 게임 JAVA (0) | 2023.09.07 |