https://school.programmers.co.kr/learn/courses/30/lessons/176963
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
보자마자 Map을 사용해야겠다고 생각이 드는 문제였다.
중간에 없는 이름에 대한 예외처리를 생각하지 못하였었다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import java.util.*;
class Solution {
public int[] solution(String[] name, int[] yearning, String[][] photo) {
int[] answer = new int[photo.length];
//Map으로 풀면 될 것 같은데?
Map<String, Integer> npList = new HashMap<>();
for(int i = 0; i < name.length; i++) {
npList.put(name[i], yearning[i]);
}
int index = 0;
for(String[] names : photo){
int point = 0;
//이름이 존재하지 않을 때
for(int i = 0; i < names.length; i++) {
if(npList.get(names[i]) == null) {
continue;
} else{
point += npList.get(names[i]);
}
}
answer[index] = point;
index++;
}
return answer;
}
}
|
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 최솟값 만들기 (0) | 2023.08.11 |
---|---|
[프로그래머스] 핸드폰 번호 가리기 (0) | 2023.05.25 |
[programmers] 최소직사각형 (1) | 2023.05.17 |
[프로그래머스] 같은 숫자는 싫어(12906) (0) | 2023.03.10 |
[프로그래머스][SQL] 그룹별 조건에 맞는 식당 목록 출력하기(131124) (0) | 2023.03.09 |